首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

c结构体有关问题

2012-08-08 
c结构体问题C/C++ code#includestdio.hstruct student{int numchar *namechar sex}s1,*psvoid main(

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");
}

热点排行