#include<stdio.h>
#include<string.h>
int main()
{
char c[]="HELLO2014";
char *p;
printf("%s\n",p+p[3]-p[1]);
return 0;
}
上面的 C 代码在 Answer 中输出 14。请解释一下如何实现?
最佳答案
这是一个技巧。
首先,您的代码片段缺少语句,您应该添加 char *p = c
;或直接使用c
在 printf
.
p[3]-p[1]
这些是字符 L 和 E,对应于 ASCII 代码中的 76 和 69。
所以你的printf
变成
printf("%s\n",p + 7 );
将 char 数组移动 7,从而 14
关于c - 打印 "p+p[3]-p[1]"的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31859575/