【发布时间】:2012-06-18 19:19:07
【问题描述】:
我不太清楚字符指针及其工作原理。
程序可以编译,但运行时崩溃。
char *ab = NULL;
//ab = "abc123"; // works fine
sprintf(ab, "abc%d", 123); // this line seems to crash the program
当 sprintf 将 (char * str) 作为第一个参数时,我不明白这是怎么回事。
谁能给我解释一下?
【问题讨论】: