【发布时间】:2010-12-04 16:24:19
【问题描述】:
为什么会输出这段代码
1234567890asdfg
asdfg
(我不能使用字符串类)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct S
{
char a[10];
char b[20];
};
int main()
{
struct S* test = (S*)malloc(sizeof(S));
strcpy(test->a, "1234567890");
strcpy(test->b, "asdfg");
printf("%s\n%s", test->a, test->b);
return 0;
}
【问题讨论】:
-
您将您的问题标记为 C,但您实际上是在使用 C++ 编译器编译它吗?你提到了字符串类,你的结构在 C 中必须被称为
struct S,而不仅仅是S。 -
是的,我正在使用 MVC++。谢谢提醒。