Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Connexion entre Tableaux et Pointers | Arithmétique des Pointeurs
C++ Pointeurs et Références

bookConnexion entre Tableaux et Pointers

Arrays and pointers are closely connected. The name of an array can be treated as a pointer to its first element.

main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { int arr[5] { 12, 21, 27, 10, 11 }; // Using dereference operator (`*`) to access the value std::cout << *(arr); }

Arrays are typically formed by arranging elements in contiguous memory blocks, where each element is stored in consecutive memory locations. This enables the application of pointer arithmetic to access any element within the array.

main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { float arr[5] { 2.7, 9.9, 1.0, 0.3, 2.2 }; std::cout << arr[3] << std::endl; std::cout << *(arr + 3) << std::endl; }

In fact, the compiler automatically performs this operation. It translates array brackets into the dereference operator with pointer arithmetic with an array name. This implies that the order can be changed, allowing the index to be placed outside the brackets while the array name remains inside the brackets (index[array_name]).

main.cpp

main.cpp

copy
1234567
#include <iostream> int main() { float arr[5] { 2.7, 9.9, 1.0, 0.3, 2.2 }; std::cout << 3[arr] << std::endl; }
Note
Note

Stick to conventional syntax for clarity, this form may confuse unfamiliar readers.

question mark

What is the connection between arrays and pointers?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 3

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookConnexion entre Tableaux et Pointers

Glissez pour afficher le menu

Arrays and pointers are closely connected. The name of an array can be treated as a pointer to its first element.

main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { int arr[5] { 12, 21, 27, 10, 11 }; // Using dereference operator (`*`) to access the value std::cout << *(arr); }

Arrays are typically formed by arranging elements in contiguous memory blocks, where each element is stored in consecutive memory locations. This enables the application of pointer arithmetic to access any element within the array.

main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { float arr[5] { 2.7, 9.9, 1.0, 0.3, 2.2 }; std::cout << arr[3] << std::endl; std::cout << *(arr + 3) << std::endl; }

In fact, the compiler automatically performs this operation. It translates array brackets into the dereference operator with pointer arithmetic with an array name. This implies that the order can be changed, allowing the index to be placed outside the brackets while the array name remains inside the brackets (index[array_name]).

main.cpp

main.cpp

copy
1234567
#include <iostream> int main() { float arr[5] { 2.7, 9.9, 1.0, 0.3, 2.2 }; std::cout << 3[arr] << std::endl; }
Note
Note

Stick to conventional syntax for clarity, this form may confuse unfamiliar readers.

question mark

What is the connection between arrays and pointers?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 3
some-alt