What is the size of int in C or C++?Answer:1) 2 byte2) system dependend3) compiler dependend

Questions by BHISMADEB   answers by BHISMADEB

Showing Answers 1 - 42 of 42 Answers

ameer

  • Dec 16th, 2006
 

minimum two bytes

  Was this answer useful?  Yes

rajat goel

  • Dec 17th, 2006
 

It is compiler dependent ... in gcc we have size of 4 bytes while in TurboC we have it as 2 bytes...Correct Answer : c

karthick

  • Dec 19th, 2006
 

It is compiller dependent.

  Was this answer useful?  Yes

mahesh

  • Dec 21st, 2006
 

3) compiler dependend

  Was this answer useful?  Yes

Manoj

  • Dec 27th, 2006
 

It is system dependent (not compiler dependent). For Linux and other Unices its 4 bytes while for windows its 2 bytes.

  Was this answer useful?  Yes

sravan

  • Jan 3rd, 2007
 

It is compiler dependent.........in case of a 16-bit compiler size of int is 2 bytes where as for a 32-bit compiler it is 4 bytes.......

  Was this answer useful?  Yes

govind

  • Jan 6th, 2007
 

2 bytes answer is a.

  Was this answer useful?  Yes

Swati

  • Jan 8th, 2007
 

It is system dependent, means processor size, 32 -bit or 16 bit, Accordingly int size will be 32 or 16 bit

  Was this answer useful?  Yes

Abhishek Sharma

  • Jan 23rd, 2007
 

The Size of any variable completely depends on the processor that is being used

for an 8-bit computing its different as for a 16-bit computer

  Was this answer useful?  Yes

Prasad JVV

  • Jan 25th, 2007
 

Size of int is dependent on both compiler and platform. If you compile a C program using Turbo C in DOS on a Pentium III Processor, then size of int is 2bytes. If you compile the same code using borland/some other compiler in windows running on the same Pentium III Processor, int size is 4 bytes. Here int size is dependent on compiler. But generally the compiler will be implemented in a way that int size is relative to the platform size. Suppose the compiler produces code such that int size is 2 on a 64-bit platform, that code can't use the features of the 64-bit, also access to the variable may be slow as the processor may need to convert from 8-byte value to 2-byte value and 2-byte value to 8-byte value. int was originally intended to be the "natural" word size of the processor - to use the processor's "natural" word size to improve efficiency. So generally size of int is also dependent on the platform as the compiler implements the size relative to the platform size.

  Was this answer useful?  Yes

akki

  • Jan 31st, 2007
 

It is system dependent not a compiler depedent, one of my friend advocate that it both compiler and system dependent, but excuse me everybody it is only system dependent, now i know one of you will arise that process is same but in dos it 2 byte, and windows it 4 byte, the answer is deceptively simple my friends, Dos is 16 bit OS, if you read about the dos( i will refer you to wikipedia), you will find it just a 16 bit operating system, which is shipped with every version of Windiws operating system. How it runs on 32 bit processer, this question is out of scope of this question, Now one my friends take a very good example, of turboC compiler and borland compiler, if you see carefully to those compiler it self, you will find that tutbo C is 16 bit compiler ( so int is there 2 byte) and borland compiler 32 bit(so int is there 4 byte). More precisly if you want to say you can say it is evironment dependent, if Environment is 16 bit you will find int 2 byte or if environment is 32 bit you find it 4 byte,

  Was this answer useful?  Yes

kbjarnason

  • Jul 1st, 2010
 

The correct answer is actually a little bit of 2 and a little bit of 3.

For example, an int has a _required_ minimum range of -32767 to 32767; this means it has to be at least 16 bits wide, even if the machine it is running on is an 8 bit machine - it's the compiler's job to sort that out.

On the other hand, 16 and 32 bit systems _typically_ have 16 and 32-bit ints, respectively, because a) they're big enough to handle the required range, and b) they're  generally the most efficient size (being the same size as the system registers).

This, of course, can be further modified.  DOS, for example, on a 386 is a 16-bit OS, even though the chip is capable of running in (and is more effcient in) 32-bit mode.  Most DOS compilers are 16-bit compilers, using 16-bit ints... but a few are 32-bit compilers with 32-bit ints.

Similarly, when you get to 64 bits, one compiler may use 64-bit ints, another may choose to use 32 bit ints; one is likely more efficient from a number-crunching perspective, the other is more likely to suit (generally poorly written) existing code.

Ultimately, the compiler is what determines the size of an int, but as a general rule, it will try to do so in a manner which is most efficient for the platform it is built for.

  Was this answer useful?  Yes

Per the C standard, an int must be able to represent at least values the range -32,767 to 32,767 (5.2.4.2.1), so an int must be at least 16 bits wide; however, it may be (and on some popular desktop systems, is) wider. 

How those bits get mapped from C data types to native bytes is determined by both the compiler implementation and underlying system.  There are still some oddball platforms out there that use byte sizes other than 8 bits, and at least a couple where the word size is not a natural multiple of the byte size (e.g., 36-bit word, 7-bit byte). 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions