What is the difference between a
, &a
and the address of first element a[0]
? Similarly p
is a pointer to an integer assigned with array's address.
Would pointer[]
do the pointer arithmetic and fetch the value as per the datatype? Further what value does *
expect? Should it be a pointer ?
#include<stdio.h>
int main()
{
int a[] = {5,6,7,8};
int *p = a;
printf("
This is the address of a %u, value of &a %u, address of first element %u, value pointed by a %u", a, &a, &a[0], *a);
printf("
This is the address at p %u, value at p %u and the value pointed by p %d", &p, p, *p);
printf("
");
}
This is the address of a 3219815716, value of &a 3219815716, address of first element 3219815716, value pointed by a 5
This is the address at p 3219815712, value at p 3219815716 and the value pointed by p 5
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…