I
Ico
Hi.I could not understand the following printf statement.Thanks for any
help.
int a=3,b=5;
printf(&a["Ya!Hello!how is this?%s],&b["junk/super]);
Neither does my compiler. If you post any code, please make sure it
compiles. I will assume you missed some quotes and ment :
printf(&a["Ya!Hello!how is this?%s"],&b["junk/super"]);
This is an old trick, not to be used in real-life code. Due to the way
arrays an pointers work in the C language, the following two lines
have the same effect:
"hello"[2]
2["hello"]
Both expressions return 'l'. If I recall correctly, the clc faq has a
detailed explanation why this is the case.
I think a equals to*[a+i].But I could not understand the use of &
In your example, the expression
&a["Ya!Hello!how is this?%s"]
is the same as
&"Ya!Hello!how is this?%s"[a]
A was set to 3 before, so this expression returns the address of the
string+3, which happens to be "Hello!how is this?%s"
The same happens with the second expression, which is used as an
argument for the %s directive in the printf format string.