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

Cursusinhoud

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

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

book
Pointers’ 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.

question mark

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

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 5

Vraag AI

expand
ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

course content

Cursusinhoud

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

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

book
Pointers’ 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.

question mark

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

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 5
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt