| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:结构体的这里,错在哪?
只看楼主 加入收藏
msl12
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2015-2-6
结帖率:25%
收藏
 问题点数:0 回复次数:6 
结构体的这里,错在哪?
# include <stdio.h>

struct Student
{
    int number;
    char name[20];
    double score;
};

int main(void)
{
    Student stu1, stu2;
    stu1={10010, "Jack", 49};//此处编译出错,为什么。。?

    return 0;
}
搜索更多相关主题的帖子: include double number return 结构体 
2015-03-21 20:31
code力力
Rank: 5Rank: 5
来 自:宜昌
等 级:职业侠客
威 望:2
帖 子:215
专家分:338
注 册:2015-1-12
收藏
得分:0 
# include <stdio.h>

struct Student
{
    int number;
    char name[20];
    double score;
};

int main(void)
{
    Student stu1, stu2;  //error
    stu1={10010, "Jack", 49};//此处编译出错,为什么。。?

    return 0;
}

struct Student才是一个类型符号。

你醒了?快起来敲代码!!
2015-03-21 20:34
longwu9t
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:732
专家分:2468
注 册:2014-10-9
收藏
得分:0 
Student stu1, stu2;
stu1={10010, "Jack", 49};

这两行都有错
下面是正确的

程序代码:
# include <stdio.h>

struct Student {
    int number;
    char name[20];
    double score;
};

int main(void) {
    struct Student stu1 = {10010, "Jack", 49}, stu2;
    return 0;
}

Only the Code Tells the Truth             K.I.S.S
2015-03-21 20:34
longwu9t
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:732
专家分:2468
注 册:2014-10-9
收藏
得分:0 
劝楼主好好静下心来看书
这些问题都是非常基础的
真想学习C的人
不会这么问的
…………………………………………………………………………………………………………

Only the Code Tells the Truth             K.I.S.S
2015-03-21 20:37
msl12
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2015-2-6
收藏
得分:0 
用VC++6.0好像不加struct也成功运行呢。。

那如果要重新改变一个结构体的值只能一个个修改结构体内部的值么?
2015-05-22 09:42
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
收藏
得分:0 
错在你把初始化用于赋值,初始化和赋值是不同的。

人有多懒,编程就有多难。
2015-05-22 10:10
文心边城
Rank: 2
等 级:论坛游民
威 望:2
帖 子:98
专家分:67
注 册:2005-12-13
收藏
得分:0 
以下是引用longwu9t在2015-3-21 20:34:56的发言:

Student stu1, stu2;
stu1={10010, "Jack", 49};

这两行都有错
下面是正确的

# include <stdio.h>

struct Student {
    int number;
    char name[20];
    double score;
};

int main(void) {
    struct Student stu1 = {10010, "Jack", 49}, stu2;
    return 0;
}

也可以写成
int main(void) {
    struct Student stu1 , stu2;
    stu1 = {10010, "Jack", 49};
    return 0;
}

会写c c++ java php JS AS vb python
2015-05-24 03:03
快速回复:结构体的这里,错在哪?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018958 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved