分类: C/C++
2009-09-08 11:20:34
/*很简单的代码,会让人很迷糊,呵呵。*/
#include
#define p(...) printf(__VA_ARGS__)
char * word[4] = {
"aaa","bbb","ccc",NULL
};
{
char **volatile wp; /*不能对这个值做优化,否则下面的打印会出错*/
wp = word;
for(;**wp!='\0';(*wp)++){ /*这个循环遍历字符串aaa*/
p("%c",**wp);
}
// p("now the **wp :%c\n",**wp);
for(;*wp!=NULL;wp++){ /*这个循环遍历aaa,bbb,ccc常量,因为在遍历aaa时已经到了'\0'的位置,所以只打印了一个换行符*/
p("%s\n",*wp);
}
p("&word:%x\n",word);
p("now wp:%x\n",wp);
p("%x\t %x\t %x\t%d\n",wp,wp++,wp=wp+1,sizeof(word));
wp++;
p("wp++:%x\n",wp);
p("**wp :%x\n",**wp);
return 0;
}
运行结果:
lzd@lzd-laptop:~/c_test$ ./a.out
aaa
bbb
ccc
&word:80496fc
now wp:8049708
8049710 804970c 804970c 16
wp++:8049714
Segmentation fault
lzd@lzd-laptop:~/c_test$ g