Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
In C++, the name of an array acts as a pointer to its first element. This close relationship is why pointer arithmetic works so well with arrays.
int arr[5] = {10, 20, 30, 40, 50};
int* ptr = arr; // ptr points to arr[0]
cout << arr[0]; // 10
cout << *arr; // 10 (Implicitly a pointer!)
cout << *(arr+1); // 20 (Same as arr[1])arr[i]The compiler actually translates this to pointer arithmetic under the hood.
*(arr + i)This is what happens internally: base address + offset.
An array name is a CONSTANT pointer. You cannot change its address (arr++ is illegal). A regular pointer can be reassigned freely.