xinex
asked on
array and pointer initilization
int *pt1,*pt2 ;
pt1=&vi2[0][0] ;
pt2=&vi2[2][1] ;
how can i rewrite right side (rvalue) i n a shorter pt1=&vi2[0][0] (more compact way).
isn't
pt1=&vi2[0][0] ;
equal to
pt1 = v2;
?
...S
pt1=&vi2[0][0] ;
equal to
pt1 = v2;
?
...S
vi2 would be an int **
pt1 is an int pointer
the value may be same or different depending on how array was allocated
consider this
int ** vi2;
vi2 = (int **) malloc (sizeof(int *) * 10 );
vi2[0] = (int *) malloc (sizeof(int ) * 10 );
now vi2[0] holds the address of [0][0] (the int we want) while vi2 holds the address of the array of pointers (not the int)
on the other hand, if the allocation was static, the addresses will be the same
pt1 is an int pointer
the value may be same or different depending on how array was allocated
consider this
int ** vi2;
vi2 = (int **) malloc (sizeof(int *) * 10 );
vi2[0] = (int *) malloc (sizeof(int ) * 10 );
now vi2[0] holds the address of [0][0] (the int we want) while vi2 holds the address of the array of pointers (not the int)
on the other hand, if the allocation was static, the addresses will be the same
Right sunnycoder,
Then how about
pt1 = *vi2
?
...S
Then how about
pt1 = *vi2
?
...S
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
pt2=&vi2[2][1]; //this is as short as it gets