Loading....
Coupon Accepted Successfully!

 

Accessing Array Elements Through Pointers

We can quickly and easily access array elements using pointers, as these elements are stored in contiguous memory locations. A pointer variable contains an address, and it is easy to manipulate data with the help of addresses. When a pointer is incremented, the address gets incremented, and we can access the contents of memory locations. This particular method requires less memory; hence, execution is fast.
 

12.5 Program to display elements of an array using pointer. Display addresses of elements.

#include<iostream.h>

#include<conio.h>

int main()

{

int *p,num[5]={1,2,3,4,5},j;
clrscr();
p=&num[0];
cout<<“\nNumber Address”<<endl;
for (j=0;j<5;j++)
cout<<“ ”<<*(p+j) <<“ ”<<unsigned(p+j)<<endl;

return 0;

}

OUTPUT
Number
1
2
3
4
5
Address
65452
65454
65456
65458
65460




Test Your Skills Now!
Take a Quiz now
Reviewer Name