0

sizeof() varies with compilers (or systems)?

sizeof() returns 4 bytes in gcc whereas it returns 2 bytes in borland version (Turbo C)

10/25/2019 8:40:41 AM

Ankit Verma

2 Answers

New Answer

+3

First thing, stop using TurboC/C++ it is an old and outdated compiler. sizeof retrun values based on target platform (32 bit or 64 bit are most common), the values are quite consistent but you will find oddity here and there. The best is never to assume the size always use sizeof to be on safe side

+2

That's because Turbo C is an ancient 16-bit compiler so an int is 16 bits (2 bytes) long. Turbo C generates 16 bit segmented memory model ms-dos binaries. Neither Turbo C nor the code it generates will run on anything more modern than Windows XP unless you use an ms-dos emulator.