<分区>
问题出在哪里?运行时,应用程序崩溃...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void test(char* x) {
(*x)++;
}
int main() {
char* x = "xD";
test(x);
puts(x);
getch();
return 0;
}
<分区>
问题出在哪里?运行时,应用程序崩溃...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void test(char* x) {
(*x)++;
}
int main() {
char* x = "xD";
test(x);
puts(x);
getch();
return 0;
}
最佳答案
您正在尝试修改存储在只读内存地址中的字符串文字,因为使用 char* x = "xD";
您声明了一个指向此类数据的指针。使用此 char x [] = "xD";
代替,它不是指针,而是一个允许修改的数组,因为它存储在堆栈中。或者,如果您想使用指针,则需要为其分配内存。
关于C - 运行此应用程序时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24587135/