CS 206 C2 Lexical Elements, Operators and the C System
Total Page:16
File Type:pdf, Size:1020Kb
CS 206 – C2 – Lexical Elements, Operators and the C System
Notes… Programming Languages (C,Fortran,Pascal,ADA,etc.) Syntax Compiler PreProcessor Tokens (keywords,identifiers,constants,string constants,operators,punctuators)
2.2 Comments (/* … */)
2.4 Identifiers (Variable Names…) 31 characters (alphabet,numbers,_ - Start with alp or _) Algorithmically Meaningful Names 2.5 Constants int – 35,-1,etc. float – 125.50,0.5e+10,etc. char – ‘a’,’/’,etc. (single chars in single quotes) hexadecimal – Ox2A,etc.
2.6 String Constants character string within double quotes
2.7 Operators and Punctuators arithmetic operators => + - * / % (Modulo) punctuators => parentheses,braces,commas,semicolons
2.8 Operator Precedence and Associativity
Multiplication/Division Higher Than Addition/Subtraction Expressions evaluated L=> R, except for …
2.9 Increment/Decrement Operators (On Identifiers Only) ++i or i++ Both => i = i + 1; ++i; Value of Expression (++i) is incremented value of i, i++; Value of Expression (i++) is original value of i.
2.10 Assignment Operators variable = expression; Double Operations… k += 2; Semantics: variable op= expression; Evaluates to variable = variable op (expression);
2.11 Powers of Two Program
2.12 The C System The PreProcessor #include
Random Number Code 2.13 Style Readable,Documented,etc.
2.14 Common Programming Errors Punctuation, Misspelled Words,etc.