【发布时间】:2021-05-06 20:18:55
【问题描述】:
我一直在解决这个问题:
#include<stdio.h>
int main()
{
printf(5 + "Good Morning ");
return 0;
}
为什么会打印 Morning?
有什么解释吗?
【问题讨论】:
-
提示:
"Good Morning "- 是指向包含字符串的内存位置的指针。剩下的就是指针算术了。 -
程序从位置5开始读取char数组。
char *p->5 + p相当于&p[5] -
改写成
char *p = "Good Morning "; printf(p + 5);会有帮助吗? -
你觉得这会打印什么
printf(0 + "Good Morning ");
标签: c printf c-strings string-literals pointer-arithmetic