1. Généralités, types de base,opérateurs et expressions

Exercice 1-1:

Quels résultats fournit le programme suivant :
#include < iostream >
using namespace std ;
main ()
{
int i, j, n ;
i = 0 ; n = i++ ;
cout << "A : i = " << i << " n = " << n << "\n" ;
i = 10 ; n = ++ i ;
cout << "B : i = " << i << " n = " << n << "\n" ;
i = 20 ; j = 5 ; n = i++ * ++ j ;
cout << "C : i = " << i << " j = " << j << " n = " << n << "\n" ;
i = 15 ; n = i += 3 ;
cout << "D : i = " << i << " n = " << n << "\n" ;
i = 3 ; j = 5 ; n = i *= --j ;
cout << "E : i = " << i << " j = " << j << " n = " << n << "\n" ;
}

Exercice 1-2:

Quels résultats fournira ce programme :

#include < iostream >
using namespace std ;
main()
{
int n=10, p=5, q=10, r ;
r = n == (p = q) ;
cout << "A : n = " << n << " p = " << p << " q = " << q << " r = " << r << "\n" ;
n = p = q = 5 ;
n += p += q ;
cout << "B : n = " << n << " p = " << p << " q = " << q << "\n" ;
q = n < p ? n++ : p++ ;
cout << "C : n = " << n << " p = " << p << " q = " << q << "\n" ;
q = n > p ? n++ : p++ ;
cout << "D : n = " << n << " p = " << p << " q = " << q << "\n" ;
}

Exercice 1-3:

Quels résultats fournira ce programme :
#include < iostream >
using namespace std ;
main()
{ int n, p, q ;
n = 5 ; p = 2 ; /* cas 1 */
q = n++ >p || p++ != 3 ;
cout << "A : n = " << n << " p = " << p << " q = " << q << "\n" ;
n = 5 ; p = 2 ; /* cas 2 */
q = n++ < p || p++ != 3 ;
cout << "B : n = " << n << " p = " << p << " q = " << q << "\n" ;
n = 5 ; p = 2 ; /* cas 3 */
q = ++n == 3 && ++p == 3 ;
cout << "C : n = " << n << " p = " << p << " q = " << q << "\n" ;
n = 5 ; p = 2 ; /* cas 4 */
q = ++n == 6 && ++p == 3 ;
cout << "D : n = " << n << " p = " << p << " q = " << q << "\n" ;
}

Exercice 1-4:

Soient les déclarations suivantes :
int n = 5, p = 9 ;
int q ;
float x ;
Quelle est la valeur affectée aux différentes variables concernées par chacune des instructions suivantes ?
q = n < p ; /* 1 */
q = n == p ; /* 2 */
q = p % n + p > n ; /* 3 */
x = p / n ; /* 4 */
x = (float) p / n ; /* 5 */
x = (p + 0.5) / n ; /* 6 */
x = (int) (p + 0.5) / n ; /* 7 */
q = n * (p > n ? n : p) ; /* 8 */
q = n * (p < n ? n : p) ; /* 9 */