Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comments Any string of symbols placed between the delimiters /* and */. Can span multiple lines Can’t be nested! Be careful. /* /* /* Hi */ is an example.

Similar presentations


Presentation on theme: "Comments Any string of symbols placed between the delimiters /* and */. Can span multiple lines Can’t be nested! Be careful. /* /* /* Hi */ is an example."— Presentation transcript:

1 Comments Any string of symbols placed between the delimiters /* and */. Can span multiple lines Can’t be nested! Be careful. /* /* /* Hi */ is an example of a comment. Keywords Reserved words that cannot be used as variable names OK within comments . . . Examples: break, if, else, do, for, while, int, void Exhaustive list in book

2 Identifiers Constants
A “token” (“word”) composed of a sequence of letters, digits, and underscore (“_”) character. (NO spaces.) Used to give names to variables, functions, etc. Identifiers such as “printf” normally would not be redefined; be careful Only the first 31 characters matter Constants Will discuss more in near future. 0, 77, examples. Strings: double quotes. “Hello” Characters: single quotes. ‘a’ , ‘z’ Have types implicitly associated with them… too large for most machines…

3 Operators and “Punctuators”
These are special characters with particular meanings, potentially depending on context + - * / are the usual arithmetic operators, and can be applied to integer types as well as floating-number types % is “mod operator”: a % b is equal to the remainder when a is divided by b, and returns a value in the range 0…(b – 1). We won’t worry about what happens when either a or b is non-positive. % character has different meaning in printf( “%d”, a ); Punctuators include parentheses, braces, semicolons… Some special operators provided by C ++, --, +=, -=. Increment/decrement, assignment… x += 2; equivalent to x = x + 2; a--; equivalent to a -= 1; Left hand side of any assignment must be “lvalue”; x + 2 is not a valid lvalue

4 Precedence of Operators
You may have learned about this in the third grade: 1 + 2 * 3 has the value of 1 + (2 * 3) If we want the addition to be performed first, must parenthesize: (1 + 2) * 3. We say that * has a higher precedence than +. See K&R page 53. Associativity of Operators Question number two: What about operators at the same precedence level? For instance, * and / ? Is 12 / 6 * 2 equal to (12 / 6) * 2, or 12 / (6 * 2) ? It’s the first: these operators are left associative (as are most) Moral of story: I say parenthesize when in doubt.

5 ++ , the tricky guy Two variants: before a variable and after.
int a = 10; printf( “%d”, a++ ); int a = 10; printf( “%d”, ++a ); I prefer personally not to mix in ++ or – as part of a more complicated expression Another complication: int a = 10; printf( “%d %d”, a++, a++ ); This complication not limited to the ++, -- operators, but occur with any operator with side effects


Download ppt "Comments Any string of symbols placed between the delimiters /* and */. Can span multiple lines Can’t be nested! Be careful. /* /* /* Hi */ is an example."

Similar presentations


Ads by Google