Possible Duplicate:
Accessing arrays by index[array] in C and C++
#include <stdio.h>
int main()
{
int a=3, b = 5;
printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);
printf(&a["WHAT%c%c%c %c%c %c !\n"], 1["this"],
2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);
return 0;
}
This is one of the practice problems that I was given in class. I’m trying to figure out how this code was able to get to the output, which is
Hello! how is this? super
That is C !
The &a[” %s”] operation. How does that work? along with the seco
The code
Is interpreted as
Since all C-style strings are pointers, this is a bizarre but legal usage of the fact that
and
are both legal in C. Consequently, the code should be interpreted as
And since
a = 3, this is the characterH. Since we take the address of this character, this gives a pointer to the C-style stringUsing this as a starting point, you can try to decode the rest of the program.
Hope this helps!