Sizeof int | SoloLearn: Learn to code for FREE!


Sizeof int

Why there is information that int takes 2 bytes, when code returns 4 ?

8/30/2017 5:52:14 PM

Tomasz Kryłowski

5 Answers

New Answer


The size is platform dependent, meaning the size can be different depending on the machine, compiler, and even operating system.


To work around that confusion, sample codes from many vendors (like Microsoft) will use CONSTANT_LITERALS to refer to the data type being used. The idea is, if you use a library that loads those literals correctly, then use the literals in your own code, you don't have to worry about it so much.


The C++11 standard introduced int8_t, int16_t, int32_t and int64_t along with their unsigned equivalents uint8_t, uint16_t, uint32_t and uint64_t. These are found in cstdint (stdint.h).


Thank you for your answers