C Language
C Language
C Language
Types dimensions
type bytes
char 1 or 2
short 2
int 2 or 4
long 4
float 4
double 8
long double 10
1
Advanced Programming 2009
Floating-point Constants
2
Advanced Programming 2009
Control statements
if-else,
switch,
while,
do-while,
for,
break,
continue
3
Advanced Programming 2009
Conditions
int x = 7;
if(x){…}
Better use relational operators
if (x != 0)
Arithmetical + - * / %
Relational > < >= <= == !=
Return 1 for true, 0 for false
Assignment = += -= *= /= %= &= |= ^=
Increment ++ --
Prefix ( ++x ) and postfix ( x++ )
Unary operators (i.e. with one operand, like ++, --) have
precedence on binary operators ( 2 operands)
Arithmetical operators have precedence on relational
operators, which have precedence on logical operators
4
Advanced Programming 2009
Logical operators
Logical operators :
&& (and)
|| (or)
! (not)
^ (xor, i.e. exclusive-or)
Bitwiseoperators work on integers interpreted
as binary numbers
& | ^ (and, or, xor)
<< (left-shift)
>> (right-shift)
~ (negation / complement)
9
Logical operators
Logical operators :
&& (and) has precedence on || (or)
! (not) is unary operator and has
precedence on all binary operators
A logical expression is evaluated from left to
right and the evaluation stops as soon as the
value is determined, e.g.:
int x= 3, y= 4;
if (x<0 && ++y>0) y += 2;
What’s the value of ‘y’ ?
10
5
Advanced Programming 2009
scanf function
6
Advanced Programming 2009
printf function
Can print variables on standard output (screen)
7
Advanced Programming 2009
8
Advanced Programming 2009
17
18