What are two ways i could assign the address of an array element [3][2] to a pointer?
Pointers in C language?
like this
int *p;
p = %26amp;array[3][2];
Reply:int *ptr;
ptr = %26amp;array[3][2];
and
int *ptr1,*ptr2;
ptr1 = %26amp;array[3][2];
ptr2 = ptr1;
Reply:int* p;
p = %26amp;a[3][2];
int* q;
q = a[3] + 2;
In the first one, the "%26amp;" just means "the address of".
In the second one, because it's a 2-dimensional array a[3] just gives me the address of the beginning of the 4th row (row 1 would be a[0]), which I just add 2 to in order to advance the address 2 places further down the row.
surveys
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment