0
2.5kviews
What is arelation between ARRAYS and pointers? Explain with example.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 4M

Year: May 2016

1 Answer
0
32views

An array is the collection of homogeneous variable assessed with common name. A pointer is a variable which contains the address of another variable.

Conside an array a[3],

enter image description here

Name of the array always points to address of the first element of an array

Since, the addresses of both are the same, the values of a and &a[0] are also the same.

a[0]=45 and

&a= 45524 then *&a=45

a[0] is equivalent to *&a.

similarly,

a[1] is equivalent to *(&a+1),

a[2] is equivalent to *(&a+2),

Example:

#include<stdio.h>
#include<conio.h>
main()
{
int a[3],i;
for(i=0;i<3;1++)
{
printf(“Enter a value:”);
scanf(“%d,&a[i]”);
}
printf(“Address of a is %u \n”,&a);
printf(“Address of a[0] is %u \n”,&a[0]);
printf(“Value of a is %d \n”,a);
printf(“Value of a[0] is %d \n”,*&a[0]);
getch();
}
Output:
Enter a value:45 
Enter a value:90
Enter a value:50
Address of a is 45524
Address of a[0] is 45524
Value of a is 45
Value of a[0] is 45
Please log in to add an answer.