Running the following code will print out orld. What is happening here? What exactly does &(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;
}
char p[] = "HelloWorld";
int i[] = {2,1,3,5,6}, j = 4;
&(p[*(i + j)]) is evaluated as below:
here i is the base address of array i. Thus i+4 will be the address of the fifth element in the array i. *(i+j) will be equal to 6. P[6] will be o after W. &(p[*(i + j)]) would be equal to &p[6]. Thus in printf you are passing the address of o and the output would be orld.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With