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

Course Content

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

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

bookPointers’ Arithmetic

Why did we go deep into arrays while learning pointers? The fact is that the array’s name is a pointer to its first element.

We can get the address of the first element of the array by its name or by declaring the pointer:

12345
int arr[5]{1, 2, 3, 4, 5}; int *p = &arr[0]; cout << p << endl; cout << arr << endl;
copy

In other words, indexing is equivalent to adding (or substructing) to the pointer:

12
cout << *(p+2) << endl; // equivalent to arr[2] cout << *(arr+2) << endl; // equivalent to arr[2]
copy

The for loop we used to go through the arrays can also be used with pointers by adding 1 on each step, but we will use these feature pointers in work with functions and dynamic memory in the following sections.

Which of the following statements can be used to get the second element of the array x?

Which of the following statements can be used to get the second element of the array x?

Select a few correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 5
some-alt