What\'s the difference between sizeof and alignof?
#include
#define SIZEOF_ALIGNOF(T) std::cout<< sizeof(T) << \'/\' << a
The two operators do fundamentally different things. sizeof
gives the size of a type (how much memory it takes) whereas alignof
gives what how many bytes a type must be aligned to. It just so happens that the primitives you tested have an alignment requirement the same as their size (which makes sense if you think about it).
Think about what happens if you have a struct instead:
struct Foo {
int a;
float b;
char c;
};
alignof(Foo)
will return 4.