int a;
int b= 3;
a= (b + 6) / 2;
printf("%i + 6 / 2 = %i", b, a);
sleep(3); // Sleep(3000) under Windows
Basic types
int: standard integer
unsigned int: unsigned integer (~ absolut value)
short, unsigned short: small integer
long, unsigned long: long integer (double of int memory size)
long long, unsigned long long: very long integer (double of long)
char, unsigned char: character (eq. very small int)
float: standard floating point number
double: more precise than float
long double:very precise floating point number (double of double)
Functions
regroups a block of instructions [return one value]
// Declaration :
//--------------
type myFct ( type param1, type param2, ...);
// Instanciation :
//----------------
type myFct ( type param1, type param2, ...)
{
instruction;
instruction;
return expression;
}
// Call :
//--------
[var= ] myFct(var1, var2, ... );
Tables
// Declaration :
//--------------
type tabName [ N ]; // number of N elements
// Declaration and assignment :
//-----------------------------
type nomTab [ N ] = {var1, ..., varN};
// one element :
//--------------
... tabName[i] ... ;
Control structures - Logic
Attention: no boolean, only integers are manipulated.
if ( condition ){
instructions;
}
else {
instructions;
}
/*
condition : int/short ... : (0)false or true
condition && condition : and
condition || condition : or
!condition : no
( condition ) : priority
comparaison operators : == < > <= >=
*/
Control structures - switch
You can see it as a succesion of several ``if ( == )''
switch ( expression ){
case value1 :
instructions;
break;
case value2 :
...
case valueN :
instructions;
break;
default :
instructions;
break;
}
Control structures - loops
Executing several-time a sucession of instriuctions: