C++ Online Compiler
Example: Array Name as Pointer Access in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Array Name as Pointer Access #include <iostream> using namespace std; int main() { // Step 1: Declare and initialize an integer array int numbers[] = {10, 20, 30, 40, 50}; int size = sizeof(numbers) / sizeof(numbers[0]); // Step 2: Access elements directly using the array name with pointer arithmetic cout << "Accessing elements using array name as a pointer:" << endl; for (int i = 0; i < size; ++i) { // (numbers + i) is equivalent to &numbers[i] // *(numbers + i) is equivalent to numbers[i] cout << "Element at index " << i << ": " << *(numbers + i) << endl; } return 0; }
Output
Clear
ADVERTISEMENTS