+ 1
question regarding pointer
int a[20]; int *p; p=&a[]; or p=&a;. or anything else for(int i=0;i<5;i++) cout<<p; how to display address of array using pointer
4 Antworten
+ 7
Array values are stored at consecutive memory addresses, i.e., one by one.
So to display an array using pointer use can add the index to the current pointer address.
Like to display a[2], you can use *(p + 2).
So your correct code will be this:
int a[20];
int[] *p;
p=&a;
for(int i=0;i<5;i++)
cout<< *(p + i);
+ 5
Vishesh Saxena Sorry I missed something.
Datatype of your pointer should int[]*
Now fixed by the edit
+ 1
thanks Zlytherin , but when i did
p=&a it shows an error
cannot convert 'int (*)[20] ' to 'int*' in assignment