Open E-School

Male
Friday, February 24, 1984

What is the size of an integer in any programming language.

Category: Programming Date: Tuesday, June 13, 2017
OpenESchool Emagazine

One of the most commonly asked question to freshers during the interview is - what is the size of an integer and a pointer. The answer to this question lies in the understanding of the architecture of the system you are working on. If you think the answer to this question is 2 bytes or 4 bytes, then this answer is partially correct and partially wrong. Why? Because the answer to this question is not absolute, it is relative to the type of compiler you are working on. 

On a 8 bit compiler the size of the integer will be 8 bits, on a 16 bit compiler the size of the integer will be 16 bit, on a 32 bit compiler the size of the integer will be 32 bit. So, when answering this question you need to mention the bit size of the compiler along with your answer.

Why does the size of integer depend on the bit size of compiler ?

The choice of the compiler depends on the type of system for which you want to write the code. If you want your code to run on a 16 bit computer, then you have to use a 16 bit compiler to compile your code. If you want your code to run on a 32 bit computer, then you have to compile your code using a 32 bit compiler.

The bit size of the compiler or the bit size of the CPU for which you are writing the code, defines the largest number which the CPU can understand. For example, the largest number that an 8 bit CPU can understand is 28-1 = 255. This means that if you are working on an 8 bit compiler, you cannot work with numbers greater than 255 because to store a number greater than 255 you will need registers bigger than 8 bits. Therefore the largest integer value which a system can understand and therefore the size of the integer is dependent on the bit size of the CPU.

To summarize

8 bit CPU has 8 bit registers and the size of integer is 8 bit. The maximum integer value which an 8 bit CPU can understand is 28-1 = 255

16 bit CPU has 16 bit registers and the size of integer is 16 bit. The maximum integer value which a 16 bit CPU can understand is 216 - 1 = 65535

Rate this article and help us improve

Please Login to rate
Overall ratings: 0 | Rating: out of 5
Previous Article Next Article

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp