【问题标题】:How to calculate the memory space occupied by the following struct?如何计算以下struct占用的内存空间?
【发布时间】:2013-04-22 01:05:29
【问题描述】:

我需要创建一个结构的内存模型,我需要找出在声明时为一个结构分配了多少内存。

struct student {       
        int Roll_no,age;
        float average;
        float grade;     
};

【问题讨论】:

  • 非常感谢问题已经解决。 :)

标签: c++ memory struct


【解决方案1】:

除非我误解了你,否则内置的 sizeof 运算符/函数可以满足你的需求:

size_t size_of_student_in_bytes = sizeof(student);

【讨论】:

    猜你喜欢
    • 2020-08-31
    • 2022-08-22
    • 2013-04-24
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 2010-10-19
    • 2013-05-26
    • 1970-01-01
    相关资源
    最近更新 更多