Page 4 - 6437
P. 4
PROGRAM STRUCTURE .............................................................................................................. 6
Hello World Example ............................................................................................... 6
Compile and Execute C Program............................................................................. 7
1. .............. BASIC SYNTAX
Tokens in C ............................................................................................................... 8
Semicolons ................................................................................................................. 8
Comments ................................................................................................................. 8
Identifiers .................................................................................................................. 9
Keywords .................................................................................................................. 9
Whitespace in C ...................................................................................................... 10
2. .............. DATA TYPES
Integer Types .......................................................................................................... 11
Floating-Point Types............................................................................................... 13
The void Type ......................................................................................................... 14
3. .............. VARIABLES
Variable Definition in C ......................................................................................... 15
Variable Declaration in C ....................................................................................... 16
Lvalues and Rvalues in C ....................................................................................... 18
4. .............. CONSTANTS AND LITERALS
Integer Literals ....................................................................................................... 19
Floating-point Literals ............................................................................................ 20
Character Constants ............................................................................................... 20
String Literals ......................................................................................................... 21
Defining Constants.................................................................................................. 22
The #define Preprocessor .......................................................................................... 22
The const Keyword ................................................................................................... 23
5. .............. STORAGE CLASSES
The auto Storage Class ........................................................................................... 24
The register Storage Class ...................................................................................... 24
The static Storage Class .......................................................................................... 25
The extern Storage Class ........................................................................................ 26
6. .............. OPERATORS
Arithmetic Operators ............................................................................................. 28
Relational Operators .............................................................................................. 30
Logical Operators ................................................................................................... 32
Bitwise Operators ................................................................................................... 34
Assignment Operators ............................................................................................ 37
Misc Operators ↦ sizeof & ternary ....................................................................... 40
Operators Precedence in C ..................................................................................... 41
7. .............. DECISION MAKING
if Statement ............................................................................................................. 46
if…else Statement ................................................................................................... 48
if...else if...else Statement ........................................................................................ 49
Nested if Statements................................................................................................ 51
switch Statement ..................................................................................................... 53
Nested switch Statements ....................................................................................... 55
The ? : Operator ..................................................................................................... 57
8. .............. LOOPS
while Loop ............................................................................................................... 59
for Loop ................................................................................................................... 61
do…while Loop ....................................................................................................... 63
Nested Loops ........................................................................................................... 65