Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Deeping into Pointers | References & Pointers
C++ Intermediate | Mobile-Friendly

bookDeeping 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:

12
cout << pb << endl; // address of the variable b cout << *pb << endl; // the value of the b
copy

The pointer always points to the address of the declared variable, and if the value of the variable changes, the address doesn’t:

1234567
int b = 2; int *pb = &b; cout << *pb << endl; b = 1; cout << *pb << endl
copy

1. Which of the following statements is true?

2. Output the address of x and then the value of x using pointers.

question mark

Which of the following statements is true?

Select the correct answer

question-icon

Output the address of x and then the value of x using pointers.

int x = 2;
int *px = &x;

cout <<
<< endl;
cout <<
;

Click or drag`n`drop items and fill in the blanks

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Ställ mig frågor om detta ämne

Sammanfatta detta kapitel

Visa verkliga exempel

Awesome!

Completion rate improved to 2.94

bookDeeping into Pointers

Svep för att visa menyn

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:

12
cout << pb << endl; // address of the variable b cout << *pb << endl; // the value of the b
copy

The pointer always points to the address of the declared variable, and if the value of the variable changes, the address doesn’t:

1234567
int b = 2; int *pb = &b; cout << *pb << endl; b = 1; cout << *pb << endl
copy

1. Which of the following statements is true?

2. Output the address of x and then the value of x using pointers.

question mark

Which of the following statements is true?

Select the correct answer

question-icon

Output the address of x and then the value of x using pointers.

int x = 2;
int *px = &x;

cout <<
<< endl;
cout <<
;

Click or drag`n`drop items and fill in the blanks

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2
some-alt