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

Зміст курсу

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

bookDeeping into Pointers

Let’s return to the previous code:

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.
Which of the following statements is true?

Which of the following statements is true?

Виберіть кілька правильних відповідей

question-icon

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

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

cout <<
<< endl;
cout <<
;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 2
some-alt