1 / 5

Comments

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 . . .

cliffordr
Download Presentation

Comments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • 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, 3.14 examples. • Strings: double quotes. “Hello” • Characters: single quotes. ‘a’ , ‘z’ • Have types implicitly associated with them… • 1234567890999 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 int a = 10; printf( “%d”, a++ ); int a = 10; printf( “%d”, ++a ); • Two variants: before a variable and after. • 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

More Related