Deeping into Pointers
Let’s return to the previous code:
int b = 42;
int *pb = &b;
Here the variable pb is a pointer. It contains the address to the variable b. Use the pointer without an asterisk to output the address the pointer contains and with an asterisk to get the value of the variable by address:
12cout << pb << endl; // address of the variable b cout << *pb << endl; // the value of the b
The pointer always points to the address of the declared variable, and if the value of the variable changes, the address doesn’t:
1234567int b = 2; int *pb = &b; cout << *pb << endl; b = 1; cout << *pb << endl
1. Which of the following statements is true?
2. Output the address of x and then the value of x using pointers.
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Stel mij vragen over dit onderwerp
Vat dit hoofdstuk samen
Toon voorbeelden uit de praktijk
Awesome!
Completion rate improved to 2.94
Deeping into Pointers
Veeg om het menu te tonen
Let’s return to the previous code:
int b = 42;
int *pb = &b;
Here the variable pb is a pointer. It contains the address to the variable b. Use the pointer without an asterisk to output the address the pointer contains and with an asterisk to get the value of the variable by address:
12cout << pb << endl; // address of the variable b cout << *pb << endl; // the value of the b
The pointer always points to the address of the declared variable, and if the value of the variable changes, the address doesn’t:
1234567int b = 2; int *pb = &b; cout << *pb << endl; b = 1; cout << *pb << endl
1. Which of the following statements is true?
2. Output the address of x and then the value of x using pointers.
Bedankt voor je feedback!