Link to home
Start Free TrialLog in
Avatar of xinex
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).
Avatar of sunnycoder
sunnycoder
Flag of India image

pt1=vi2[0] ;

pt2=&vi2[2][1]; //this is as short as it gets
Avatar of snehanshu
snehanshu

isn't
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
Right sunnycoder,
Then how about
pt1 = *vi2
?
...S
ASKER CERTIFIED SOLUTION
Avatar of dennis_george
dennis_george
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial