c结构体问题
- C/C++ code
#include<stdio.h>struct student{ int num; char *name; char sex; }s1,*ps;void main(){ s1={210,"Tom",'M'}; ps=&s1; printf("%d\n",ps->num); system("pause");}错误提示:Expression syntax in function main
请问为什么s1赋值不对?
[解决办法]
#include<stdio.h>
typedef struct student
{
int num;
char name[4];
char sex;
}s,*p;
int main()
{
s s1 ={210,"Tom",'M'};//初始化时才可集体赋值
p ps = &s1;
printf("%d\n",ps->num);
system("pause");
}