# C Programming Language ![rw-book-cover](https://images-na.ssl-images-amazon.com/images/I/51cm0z-4qpL._SL200_.jpg) ## Metadata - Author: [[Brian W. Kernighan and Dennis Ritchie]] - Full Title: C Programming Language - Category: #c ## Highlights - C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly. ([Location 286](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=286)) - A C program, whatever its size, consists of functions and variables. ([Location 348](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=348)) - A function contains statements that specify the computing operations to be done, and variables store values used during the computation. ([Location 348](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=348)) - One method of communicating data between functions is for the calling function to provide a list of values, called arguments, to the function it calls. ([Location 359](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=359)) - A sequence of characters in double quotes, like "hello, world\n", is called a character string or string constant. ([Location 380](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=380)) - Notice that \n represents only a single character. An escape sequence like \n provides a general and extensible mechanism for representing hard-to-type or invisible characters. ([Location 395](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=395)) - In C, all variables must be declared before they are used, usually at the beginning of the function before any executable statements. ([Location 431](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=431)) - A declaration announces the properties of variables; it consists of a type name and a list of variables, such as ([Location 432](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=432)) - C provides several other basic data types besides int and float, including: char         character—a single byte short       short integer long          long integer double     double-precision floating point ([Location 441](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=441)) - We recommend writing only one statement per line, and using blanks around operators to clarify grouping. ([Location 470](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=470)) - The reason for multiplying by 5 and then dividing by 9 instead of just multiplying by 5/9 is that in C, as in many other languages, integer division truncates: any fractional part is discarded. Since 5 and 9 are integers, 5/9 would be truncated to zero and so all the Celsius temperatures would be reported as zero. ([Location 476](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=476)) - If an arithmetic operator has integer operands, an integer operation is performed. If an arithmetic operator has one floating-point operand and one integer operand, however, the integer will be converted to floating point before the operation is done. ([Location 529](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=529)) - writing floating-point constants with explicit decimal points even when they have integral values emphasizes their floating-point nature for human readers. ([Location 532](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=532)) - Among others, printf also recognizes %o for octal, %x for hexadecimal, %c for character, %s for character string, and %% for % itself. ([Location 559](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=559)) - One way to deal with magic numbers is to give them meaningful names. A #define line defines a symbolic name or symbolic constant to be a particular string of characters: #define  name  replacement text Thereafter, any occurrence of name (not in quotes and not part of another name) will be replaced by the corresponding replacement text. The name has the same form as a variable name: a sequence of letters and digits that begins with a letter. The replacement text can be any sequence of characters; it is not limited to numbers. ([Location 602](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=602)) - The quantities LOWER, UPPER and STEP are symbolic constants, not variables, so they do not appear in declarations. ([Location 619](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=619)) - Text input or output, regardless of where it originates or where it goes to, is dealt with as streams of characters. A text stream is a sequence of characters divided into lines; each line consists of zero or more characters followed by a newline character. ([Location 625](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=625)) - This value is called EOF, for “end of file.” We must declare c to be a type big enough to hold any value that getchar returns. We can’t use char since c must be big enough to hold EOF in addition to any possible char. Therefore we use int. ([Location 661](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=661)) - EOF is an integer defined in <stdio.h>, but the specific numeric value doesn’t matter as long as it is not the same as any char value. ([Location 666](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=666)) - This means that an assignment can appear as part of a larger expression. If the assignment of a character to c is put inside the test part of a while loop, ([Location 673](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=673)) - The precedence of != is higher than that of =, which means that in the absence of parentheses the relational test != would be done before the assignment =. ([Location 688](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=688)) - presents a new operator, ++, which means increment by one. ([Location 709](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=709)) - The operators ++ and -- can be either prefix operators (++nc) or postfix (nc++); these two forms have different values in expressions, ([Location 712](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=712)) - A character written between single quotes represents an integer value equal to the numerical value of the character in the machine’s character set. ([Location 762](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=762)) - If the expression is true, statement1 is executed; if not, statement2 is executed. Each statement can be a single statement or several in braces. In the word count program, the one after the else is an if that controls two statements in braces. ([Location 826](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=826)) - By definition, chars are just small integers, so char variables and constants are identical to ints in arithmetic expressions. ([Location 871](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=871)) - The conditions are evaluated in order from the top until some condition is satisfied; at that point the corresponding statement part is executed, and the entire construction is finished. ([Location 891](https://readwise.io/to_kindle?action=open&asin=B009ZUZ9FW&location=891))