The C Programming Language

Author: Brian W. Kernighan, Dennis M. Ritchie
4.6
All Stack Overflow 79
This Year Reddit 70
This Month Reddit 3

Comments

by jojotv   2019-11-17

If you're into robotics, Python, C, and C++ are all equally useful.

If that's the case, and you can learn all three, I would learn C first using this book. After that, I would move on to Python. After you feel comfortable with Python, learn modern C++.

If you can only learn one, go with Python.

by MattR47   2019-11-17

This one.

C Programming Book

by [deleted]   2019-11-17

The C Programming Language

by PrincessWinterX   2019-11-17

I quite like the book written by the developers of the language themselves. The C programming language.

by Updatebjarni   2019-11-17

K&R is the book for C, especially if you have prior programming experience.

by Bizkitgto   2019-11-17

If you want to learn C, you can follow along with Harvard's CS50 (the beginning in all about C). If you like it, you can do the entire course for free here.

Also, you should pick up the Bible of C Programming, KnR C Programming.

by cbasschan   2019-08-24

No, you don't... and no, it isn't. Stop listening to these literary nobodies and start listening to your book. I asked which one you're reading because it seems like the method you're using to learn isn't working for you (hence, you asked this question here, which people who read books wouldn't usually ask).

Look, I see this a lot. It would seem far too many people want to learn "the C programming language" purely by studying one rather common implementation... and so they end up learning a subset of the language which has subtle non-portable quirks that evolve a life of their own over time, perhaps becoming bugs or security issues.

C does not have pass-by-reference. I shouldn't need to point out that passing a reference type by value is still pass-by-value, because that should be written in your textbook somewhere. Take a look at this page if you'd like to know more about the difference between pass-by-reference and pass-by-value.

>By definition, pass by value means you are making a copy in memory of the actual parameter's value that is passed in, a copy of the contents of the actual parameter.

I predict a response similar to the following:

>... ok but C allows you to mimic pass-by-reference using pass-by-value ...

A turing complete language can mimic any other turing complete language, by definition. What can't happen is a reliable conversation in English if we don't agree upon the definitions for the words we use... and I quote, from the C11 standard, section 6.5.2.2

>In preparing for the call to a function, the arguments are evaluated, and each parameter is assigned the value of the corresponding argument

This squarely describes the assignment of a copy into a temporary or intermediate space ("the corresponding argument"), i.e. clearly pass-by-value...

by cbasschan   2019-08-24

Indeed, it's good to see I'm not the only one who strongly dislikes this website...

> Strings in C are the collection of characters. Strings are also known as an "Array of Characters".

​

That is utter nonsense! Quoting the C standard, you can see why:

C11/7.1.1p1: > A string is a contiguous sequence of characters terminated by and including the first null character. The term multibyte string is sometimes used instead to emphasize special processing given to multibyte characters contained in the string or to avoid confusion with a wide string. A pointer to a string is a pointer to its initial (lowest addressed) character. The length of a string is the number of bytes preceding the null character and the value of a string is the sequence of the values of the contained characters, in order.

​

There are multiple contradictions in the implication your website creates. Let us look at them in order specified above:

​

C11/7.1.1p1: >A string is a contiguous sequence of characters terminated by and including the first null character.

​

Where in your definition have you mentioned the terminating null character? Note that this implies a string doesn't necessarily span the entirety of the array and a string doesn't necessarily reside within an array at all.

C11/7.1.1p1: >A pointer to a string is a pointer to its initial (lowest addressed) character.

​

If we interpret your website literally, then a pointer to a string is a pointer to an array of characters. The declaration of a pointer to an array of n characters named unusual_string_pointer looks like this:

char (*unusual_string_pointer)[n];

​

This is unusual because it's very unlike the argument type accepted by our standard string functions. In addition to the implications I've mentioned earlier, from this most recent quote from the standard we can tell a string might begin mid-way through an array.

>The length of a string is the number of bytes preceding the null character and the value of a string is the sequence of the values of the contained characters, in order.

It's extremely common for newcomers to categorically confuse the concepts of strings and arrays, such that they believe strlen(string_in_array) would be sizeof string_in_array - 1. That is not necessarily the case, as this quote shows, yet your website does nothing to guide beginners past this common hurdle.

Moving on to some other quotes within your page here...

>Strings in C is a one-dimensional array.

It is trivial to construct a string that isn't stored within an array. With the caveat that the only safe string (that I can think of) to do this with is an empty string, and that you'll probably want to use the &address-of operator to do this, I'll leave this to you as an exercise. The key take-home point here is strings are (typically) stored in arrays, but aren't the arrays. You could say that prime numbers are (typically) stored in int, but that's not necessarily always the case.

>Strings in C are ended by the "NULL ('\0') character. >Strings are written in double quotes ("Programming") while the character is written inside a single quote ('A').

I wonder why you would assume the position of a teacher whilst confusing string literals for strings like this. Tell me, why isn't "Programming" ended by the "NULL ('\0') character in this text? To me it seems like you have two definitions merged into one, and they're contradicting each other.

I would also like to add that one example of a string (using the formal definition from 7.1.1p1 above) can be written using a character literal like so: '\0' (this is a hint for your exercise). A pointer to that string (also complying with the definition) can be written, without a declaration... and the length of that string (see 7.1.1p1 for this definition) can be written... all without declaring a single variable.

C11/footnode 78: >A string literal need not be a string (see 7.1.1), because a null character may be embedded in it by a \0 escape sequence.

As you can see from footnote 78, an attempt to place a \0 terminating character into a string literal is likely to cause a string literal that isn't a string. Furthermore, if we use string literals as initialisers for arrays that aren't large enough to store the terminating byte, the string literal won't be treated like a string, for example: char fubar[5] = "fubar"; // not a string.

Further common confusions appear in reality with our students, such that newcomers tend to think an array of characters is automatically a string and thus automatically contains a terminating null character... more utter nonsense which your website does nothing to quench... and to be clear on this, I expect more from an educator and was shocked to find you work at a university, teaching programming! This was the point at which I decided to start reporting you for misleading people (and plagiarism). You need to go back to university, as a student, and study C properly (without cheating on your exams).

To be clear on this, if you're going to use the writings of other people (like myself), you need to properly cite those writings. We've been down this road before; I threatened you with DMCA takedown, remember? Frankly, you disgust me. Our educators should know better... to think I am unemployed on a disability pension while you are employed in my dream position. You disgust me!

Even despite earlier making the erroneous statement that Strings are also known as an "Array of Characters", you go on to say...

> In C programming, strings are not used as a data type (like char, float, double, int etc.).

Don't you realise "Array of Characters" is a data type? You have mixed this last small ounce of truth that this page contains in gallons of utter rubbish, as demonstrated by the very next statement you make:

> Strings are declared like an array if you do not know what the arrays are? Then, first, you should read the arrays.

You're a hypocrite. If you don't know what constitutes C, then, prior to assuming the role of an I.T. professors assistant, you should read a book about C (and do the exercises, as you would expect of your students).

I'm not going to bother correcting all of your errors. It'd be less wasteful of my time to simply write my own textbook, and to be clear on that matter, there's nothing wrong with K&R2E. Your website exists without a purpose, and lies to people. What you should do, to be honest to your students and to the founding forefathers of the language, is redirect your entire domain to the Amazon page for K&R2E. Make an affiliate link, if you like, so that you get commissions on the sales... at least this way your students will learn the *actual** programming language, as opposed to your retarded imagination of it*.

by TheHyperB3ast   2019-08-24

K&R. If you're in a programming 101 class that involves C, just buy this book unless your prof tells you otherwise.

K&R has the reputation it has because they did an excellent job of balancing between "experienced programmers can use this as a reference" and "newbie programmers can use this as a starting point. Let me clarify: K&R will not make you a better programmer, but it is an excellent example of what industry professionals would consider to be a good piece of technical documentation.

If you're going to ever work with APIs or large amounts of technical documentation about software, this book will mirror the experience you get reading "good docs". In short, learning C from this books does an excellent job of showing you how much you'll have to figure out yourself and what information you should be expected to be given to you when working in the industry.

by MrNeurotypical   2019-07-21

I found it much easier to learn C first and then C++

https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

​

BTW I don't use C++ anymore, just python and BASH.

by farrp2011   2019-07-21

https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

by mawattdev   2019-07-21

Read K&R C and work through the examples. C Programming Language, 2nd Edition https://www.amazon.com/dp/0131103628/ref=cm_sw_r_cp_apa_i_KsHRCbMHMDBX8

by ekollof   2019-07-21

This is your new bible:

https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

​

​

by pdoherty926   2019-07-21

I haven't read either of those, but I did enjoy and find a lot of value in K&R and 21st Century C.

by anonymous   2019-07-21

Since Objective C is an expansion of C, I suggest the C 'bible' from Kernichan and Ritchie.

http://www.amazon.com/C-Programming-Language-2nd-Edition/dp/0131103628

by anonymous   2019-07-21

K & R. [Kernighan & Ritchie]

http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628/ref=pd_bbs_1?ie=UTF8&s=books&qid=1240539543&sr=8-1

by Hymnosi   2019-07-21

You would probably benefit from a systems manual, on top of a general syntax book like K&R.

http://www.amazon.com/gp/product/0131103628

https://www.amazon.com/Programming-Environment-Addison-Wesley-Professional-Computing/dp/0201563177

this is not based on any experience, just some research I did on my own. Unfortunately most C programming knowledge is locked up in textbooks or in reference documents. There isn't a ton of walkthrough style manuals for the language, despite how old it is.

by Nicholas-DM   2019-07-21

C and Python are both used lots, and are good choices. C++ is beautiful and difficult, and there is a shortage of excellent material to learn from.

If you go with C, which is fast and great and, on its own, relatively easy to learn, the following book is likely the best way to learn it. It is known affectionately as the 'K&R Bible'.

https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

If you go with Python, most resources will teach you a decent chunk decently well. You'll likely have trouble moving to intermediate complexity programming, but will be able to find guidance when you get to it.

Good luck and have a great day!

by ijustwantanfingname   2019-07-21

https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

It's very, very worthwhile if you're learning C. A bit dry, but very concise and easy to understand.

by anonymous   2019-07-21

Just read The C Programming Language and write code. If you're new to it then you need first-hand experience so you can learn what the subtleties are. Just reading a list won't help a huge amount.