In C programming language a most common keyword ‘int’ is used to define any positive or negative integer. But there is a difference between an integer and the numbers which can be represented with the help of the keyword ‘int’. Not every integer can be represented with the keyword ‘int’. According to MinGW the size of one ‘int’ is 4 bytes which is equal to 32 bits (1 byte=8 bits). It is still a myth somewhere that ‘int’ can represent an integer or ‘int’ is used to represent integers. Integer is a very vast category of numbers where as one ‘int’ has limited and exact amount of memory (size of ‘int’ is 4 bytes or 32 bits) to store what is being represented by it. An ‘int’ type variable in C language is able to store only numbers till 2147483647. Beyond this number ‘int’ fails to store precisely and even not correctly. ‘int’ is a 32 bit data type. Whenever a number is being assigned to an ‘int’ type variable, it is first converted to its binary representation (that is in 0’s and 1’s) then it is kept in memory at specific location. An ‘int’ is actually 1 sign bit + 31 data bits, that is 31 bits are available for storing the number being assigned to a ‘int’ type variable and 1 bit is reserved for maintaining the sign of the number which is either + or – . The sign is also represented by binary digits, 0 for positive sign and 1 for negative sign.
Let us understand this by an example.
Example – Consider,
At this point first 2147483647 will be converted into its binary form which is equal to:
1111111111111111111111111111111 is a 31 digit binary number which will be assigned to variable num’s right most 31 bits and the 32nd bit will have a zero(0) as the number being assigned to variable num is a positive number. If we try to store any number greater than 2147483647 into an ‘int’ type variable then we will lose information.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between const int*, const int * const, and int const *
- Difference between "int main()" and "int main(void)" in C/C++?
- Difference between sizeof(int *) and sizeof(int) in C/C++
- How to compile 32-bit program on 64-bit gcc in C and C++
- Understanding "extern" keyword in C
- Understanding "register" keyword in C
- Use of explicit keyword in C++
- Function overloading and const keyword
- C++ mutable keyword
- C++ | Static Keyword | Question 1
- C++ | Static Keyword | Question 2
- C++ | friend keyword | Question 1
- C++ | friend keyword | Question 2
- C++ | Static Keyword | Question 4
- C++ | const keyword | Question 1
- C++ | const keyword | Question 2
- C++ | const keyword | Question 3
- C++ | Static Keyword | Question 5
- C++ | const keyword | Question 5
- C++ | Static Keyword | Question 6
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.