【发布时间】:2016-07-01 11:52:46
【问题描述】:
以下代码在第二行给出了段错误:
char *tester = "hello";
char a = (*tester)++; // breaks here
printf("Char is %c\n", a);
以下代码有效:
char *tester = "hello";
a = *tester;
a++;
printf("Char is %c\n", a);
// prints i
为什么不能一次完成?
【问题讨论】:
-
tester是char *。(*tester)是一个常量字符。您正在尝试增加一个常量字符。