Sizeof int | SoloLearn: Learn to code for FREE!

0

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

+13

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

+5

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.

+3

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).

+2

Thank you for your answers

+1

https://code.sololearn.com/cubc84c8JQCv/?ref=app https://code.sololearn.com/cBss8k5523i1/?ref=app