我很想知道为什么下面的代码片段适用于某些 C 编译器而不是其他的。我的教授可以在 DevC++ 中编译此代码,我也可以,但我无法在 VS 2010 中编译此代码。有什么想法吗?VS 说 a.word 有一个错误的指针。我假设 VS 疯了,因为我没有初始化 a.word,但为什么代码在 DevC++ 中编译和工作?我必须添加 a.word=""; 在 strcpy 之前,然后它在 VS 中工作,但我再次很想知道为什么。谢谢
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct foo{ int num;
char* word;
struct foo *ptr;};
int main() {
struct foo a;
a.num = 5; a.ptr = &a;
strcpy(a.word,"whichword");
}