| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 423 人关注过本帖
标题:请假sizeof问题
只看楼主 加入收藏
youtk21ai
Rank: 1
等 级:新手上路
帖 子:13
专家分:5
注 册:2010-4-8
结帖率:80%
收藏
已结贴  问题点数:10 回复次数:1 
请假sizeof问题
#include "iostream.h"
#include "iomanip.h"

struct  student
{
    char id[10];
    char name[20];
    char sex;
    int age;
    char department[30];
    float score;
};

void main(){
    student student1 = {"05030100","WangWei",'M',20,"Computer",95},
        student2 = {"05030101","LiMing",'M',21,"Physic",98};
    float average;
    cout<<student1.age<<" "<<student1.department<<" "<<student1.id<<" "<<student1.name<<" "<<student1.score<<" "<<student1.sex<<endl;
    cout<<student2.age<<" "<<student2.department<<" "<<student2.id<<" "<<student2.name<<" "<<student2.score<<" "<<student2.sex<<endl;
    average = (student1.score+student2.score)/2;
    cout<<"average="<<average;
    cout<<"sizeofstudent1="<<sizeof(student1)<<endl;
}

为什么sizeof(student1)=72?
搜索更多相关主题的帖子: sizeof 请假 
2010-06-06 03:19
迷失的木桶
Rank: 4
等 级:业余侠客
帖 子:52
专家分:230
注 册:2010-5-29
收藏
得分:10 
字节对齐而已,默认4的整倍数,谷歌一下多的是,呵呵
2010-06-06 08:13
快速回复:请假sizeof问题
数据加载中...
 
   



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

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