c - What exactly does &(p[*(i + j)]) do? -
running following code print out orld
. happening here? &(p[*(i + j)])
do?
#include <stdio.h> char p[] = "helloworld"; int i[] = {2,1,3,5,6}, j = 4; int main() { printf(&(p[*(i + j)])); return 0; }
i'll try simplify step step
#include <stdio.h> char p[] = "helloworld"; int i[] = {2,1,3,5,6}, j = 4; int main() { printf(&(p[*(i + j)])); return 0; }
the first 3 lines obvious:
p
array of 10 charactersi
array of 5 integersj
integer , has value 4
printf(&(p[*(i + j)]));
is same as
printf(&(p[*(i + 4)]));
is same as
printf(&(p[*([adress of first element of i] + 4)]));
is same as
printf(&(p[*([adress of fourth element of i])]));
now have know *address
gives value in address
. so:
printf(&(p[6]));
now that's point guess struggling. have know:
- arrays nothing else part in memory continuous. specified it's starting address.
&something
gives address ofsomething
so "slices" array helloworld
orld
. in python write p[6:]
, in c write &p[6]
.
Comments
Post a Comment