#include <stdio.h>
int main()
{
int a=3, b = 6;
printf(&a["Hi!Hello! %s\n"], &b["Mnnit/Softathalon"]);
printf(&a["WHAT%c%c%c %c%c %c !\n"], 1["this"],
2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);
return 0;
}
output:
Hello! Softathalon
That is C !
Why is this the output? Can anyone explain different format specifier in it?
For any array
T arr[N], the expressionarr[i]is equivalent to*(arr + i).Because the addition is commutative in the latter expression, you can also write this as
*(i + arr), and hence asi[arr].In particular,
arr[3]and3[arr]denote the same thing.It’s one of those “curiously funny things you can do in C”, but it should go without saying that serious code should never actually use such a construction.