#include<stdio.h>
main()
{
char c = 'R';
printf("%c\n",c);
c++;
printf("%c\n",c);
char *ptr ="Ramco Systems";
printf("%c\n",(*ptr));
(*ptr)++;
printf("%d\n",(*ptr));
}
第一,第二,第三printf的输出为'R','S'&'R'(如预期的那样)。然而行“(* ptr)++;”给运行时错误。有人能解释为什么吗?增加指针时的模糊行为
它看起来不像是在递增指针。您取消引用指针并递增值。 –
我想你想要的是* ptr ++ :) – useratuniv
我认为目标是将'R'增加到下一个ansi字符,所以代码中没有错字 - 只是指针指向的内存是不可修改的。 – jwaliszko