hyetpang 2016-04-27 01:47 采纳率: 39.4%
浏览 1614

关于c++结构体长度的问题

#include <iostream>

using namespace std;

struct Student{
    char ch;
    int i;
}st1;

struct name{

}n;

struct j{
    static int i ;
}l;

struct nam{
    static int i;
}e;

struct Studen{

}st;


int main(){
    int s = sizeof(st1);
    int n2 = sizeof(n);
    int l = sizeof(l);
    int e1 = sizeof(e);
    int se = sizeof(st);
    printf("%d %d  %d %d %d", s, l, n2, e1, se);
    return 0;
}

在这个程序中,第二个输出的数字为什么是4呢?不应该是1么?

  • 写回答

5条回答 默认 最新

  • threenewbee 2016-04-27 01:50
    关注

    结构体按照4字节的倍数对齐。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog