What's the difference between sizeof and alignof?

后端 未结 7 1545
遥遥无期
遥遥无期 2020-12-23 17:19

What\'s the difference between sizeof and alignof?

#include 

#define SIZEOF_ALIGNOF(T) std::cout<< sizeof(T) << \'/\' << a         


        
7条回答
  •  长情又很酷
    2020-12-23 17:45

    The alignof value is the same as the value for sizeof for basic types.

    The difference lies in used defined data types such as using struct; for an e.g.

    typedef struct { int a; double b; } S;
    //cout<

    hence the sizeof value is the total size required for the given data type; and alignof value is the alignment requirement of the largest element in the structure.

    Use of alignof : allocate memory on a particular alignment boundary.

提交回复
热议问题