C Language

Integer Overflow

In C Language by Baqir AliLeave a Comment

Integer Over Flow

At run-time, a variable may be assigned an incorrect value. The logical value of the expression b+c is 4 billion, which is greater than the maximum value which can be stored in a variable of type int. This is known as an integer overflow

int b = 2000000000, c =2000000000;   
a = b + c;   /* out of range */ 

How do we fix this problem?

What if we declare:

long a, b = 2000000000, c = 3000000000;
Or
unsigned long a, b = 2000000000, c = 2000000000;  

Support us by sharing this post

About the Author

Baqir Ali

Facebook Twitter

Hi, I am Baqir Ali ---- Blogger, Programmer, and a Teacher. I am currently working as a Programmer for Softnat Technologies. I have tons of ideas and data to share with you all via blogging.

Leave a Comment