i'm new programming. code not working want, retrieve 1-d array address 2-d array:
#include<stdio.h> main() { int s[4][2] = { { 1234, 56 }, { 1212, 33 }, { 1434, 80 }, { 1312, 78 } }; int ; ( = 0 ; <= 3 ; i++ ) printf ( "\naddress of %d th 1-d array = %u", i, s[i] ) ; }
to more precise , not using c feature array passed pointer function (printf()
here), can use pointer array here:
for ( = 0 ; < 4 ; i++ ) { int (*ptr)[2] = &(s[i]); printf ( "\naddress of %d th 1-d array = %p\n", i, (void*)ptr) ; }
the difference between s[i]
, &(s[i])
is, s[i]
is 1d array, type int[2]
, &(s[i])
pointer int[2]
, want here.
you can see it, example, sizeof
operator: sizeof(s[i])
2 * sizeof(int)
here, sizeof(&(s[i]))
has size of pointer variable.
Comments
Post a Comment