Variables and Expressions
Practical C chapter 4, K&R chapter 2.
Variables
- names: letters, numbers, and underscores. start with letter. case sensitive, as is everything in C (and UNIX in general).
- types
- int (Integers are whole numbers)
- float (numbers with a decimal point)
- type conversion
- char
- escape sequences:
\b \f \n \r \t \' \" \\ \a
- (arrays)
- string
- an array of characters
- null termination
- printf:
%d
(decimal integer)
%f
(floating point)
%c
(character)
%s
(string)
Operators
- arithmetic:
* / + - % ++ --
- logical:
> >= < <= == != && || !
- ternary
x = e ? a : b
is the same as if (e) { x = a } else { x = b }
- shortcuts:
+= -= *= /= %=
- precedence