#include using namespace std; int main(int argc, char **argv) { int i = 9; cout << "Contenu de i: '" << i << "'" << endl; cout << "Adresse de i: '" << (unsigned int)&i << "'" << endl << endl; /* On declare un pointeur sur int et on lui * affecte l'adresse de i. On dit que p * pointe sur i. */ int *p = &i; cout << "Contenu de p: '" << (unsigned int)p << "'" << endl; cout << "Adresse de p: '" << (unsigned int)&p << "'" << endl; cout << "Contenu de la variable pointee par p: '" << *p << "'" << endl << endl; // On affecte 10 a l'adresse pointee par p. *p = 10; cout << "Contenu de la variable pointee par p: '" << *p << "'" << endl; cout << "Contenu de i: '" << i << "'" << endl; // Partie a completer // 3. i incrementee de 10 cout << "3." << endl; *p = *p + 10; cout << "Contenu de i: '" << i << "'" << endl; // 4. nouveau pointeur sur i cout << "4." << endl; int *q = p; cout << "Contenu de la variable pointee par q: '" << *q << "'" << endl; // 5. echange cout << "5." << endl; float f = 5; int t = *p; *p = int(f); f = t; cout << "Contenu de i: '" << i << "'" << endl; cout << "Contenu de f: '" << f << "'" << endl; // 6. echange (2) cout << "6." << endl; int j = 8; q = &j; int k = *q; *q = *p; *p = k; cout << "Contenu de i: '" << i << "'" << endl; cout << "Contenu de j: '" << j << "'" << endl; // Fin de la partie a completer return 0; }
- Sunday
- November 3rd, 2024
- Ajouter un cours