#include <stdio.h>
#include<stdlib.h>
int main()
{
int a=3, b = 5;
//[]优先级比&高所以 &a["Ya!Hello! how is this? %s\n"] 等价于 &(*(a + "Ya!Hello! how is this? %s\n")
//因为a == 3,所以(a + "Ya!Hello! how is this? %s\n") 向右偏移了4个字节到达H下面
//然后遇到*解除引用
所以
*(a + "Ya!Hello! how is this? %s\n") == 'H'
//然后又遇到&取得了指向存放'H'的ASCII码的内存地址由于该地址又是"Hello! how is this? %s\n"的首地址
//所以&a["Ya!Hello! how is this? %s\n"] == "Hello! how is this? %s\n";
//[]优先级比&高所以 &b["junk/super"] 等价于 &(*(b + "junk/super"))
//因为b == 5,所以(b + "junk/super") 向右偏移了6个字节达到's'下面
//然后遇到*解除引用
所以
*(b + "junk/super") == 's'
//然后又遇到&取得了指向存放's'的ASCII码的内存地址
由于该地址又是"super"的首地址
//所以&b["junk/super"] == "super";
//所以printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);的结果为:
/*
*
Hello! how is this? super (换行)
*/
printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);
//比上面的还要简单
//&a["WHAT%c%c%c
%c%c
%c !\n"] == &(*(a + ""WHAT%c%c%c
%c%c
%c !\n")) == "T%c%c%c %c%c %c !\n"
printf(&a["WHAT%c%c%c
%c%c
%c !\n"],
//1["this"] == *(1 + "this") == 'h'
1["this"],
//2["beauty"] == *(2 + "beauty") == "a"
2["beauty"],
//0["tool"] == *(0 + "tool") =='t'
0["tool"],
//0["is"] == *(0 + "is") == 'i'
0["is"],
//3["sensitive"] == *(3 + "sensitive') == 's'
3["sensitive"],
//4["CCCCCC"] == *(4 + "CCCCCC") == "C"
4["CCCCCC"]);
/*****************************************
*
结果为
*
That
is
C ! (换行)
*
*
其实就是运算符'优先级'和'[]'(变址运算符迷惑了我们)
*
*****************************************/
system("pause");
return 0;
}