#include <iostream> using namespace std; int main() { int A[5] = {10,20,30,40,50}; int *p , *ptr; p = A; ptr = &A[0]; /* no need to give the ampersand(&) when we are giving array name to the pointer, because name of an array A itself is the starting address of this array. So, p is the pointer so, it can store the address. If we want to use ampersand(&) then we should say A of zero, A[0] means this to 10, A[0] is 2 and its address, then you should write the address. */ for (int i=0; i<5; i++) { cout << A[i] << endl; //To access the values using pointer instead of array name: // cout << p[i] << endl; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter