Tavoite: Opin käyttämään C++:n osoittimia.
Ohjeita: Tarkastele esimerkkikoodeja ja merkitse todet väittämät.
Tarkastele alla olevaa koodia:
1 2 3 4
int x = 3; int* ptr = &x; cout << ptr << endl; cout << *ptr << endl;
Valitse todet väittämät yllä olevan koodin perusteella.
1 2 3 4 5
int x; int* ptr = &x; x = 4; cout << ptr << endl; cout << *ptr << endl;
int x; int* ptr = &x; *ptr = 4; cout << ptr << endl; cout << *ptr << endl;
int x; int* ptr = 4; cout << ptr << endl; cout << *ptr << endl;
1 2 3 4 5 6 7
int x; int* ptr = &x; x = 5; cout << ptr << endl; cout << *ptr << endl; cout << x << endl; cout << &x << endl;