About array names and addresses of arrays in C -
i had following code :
#include<stdio.h> void main() { int * a; int arr[2]; arr[1] = 213 ; arr[0] = 333 ; = &arr ; printf("\narr %d",arr); printf("\n*arr %d",*arr); printf("\n&arr %d",&arr); printf("\n%d",a[1]); }
on running simple program output follows :
arr -1079451516 *arr 333 &arr -1079451516 213
why both arr , &arr give same result ? can understand arr memory location , *arr or arr[0] value stored @ position, why &arr , arr same ?
almost time use expression array type, "decays" pointer first element. arr
becomes pointer type int*
, , pointer what's passed printf
. &arr
pointer type int (*)[2]
(pointer array of 2 int
s). 2 pointers have same address, since both point @ beginning of array.
(one notable exception array-to-pointer conversion in sizeof
argument.)
Comments
Post a Comment