Overflow and Underflow

Default Image

verflow is a case where operations on 2
numbers exceeds the maximum (or goes below the minimum) value the data
type can have. Usually it is assumed that integral types are very large,
and user don’t consider that sum of two numbers can be larger than the
range. If the size of a data type is n bytes, it can store 28n different values. This is called the data type’s range. If size of an unsigned data type is n bytes, it ranges from 0 to 28n-1. If size of a signed data type is n bytes, it ranges from -28n-1 to 28n-1-1. So, a short (usually 2 bytes) ranges from -32768 to 32767 and an unsigned short range from 0 to 65535. For example:

#include


#include


void main()


{


int a=97482, b=-62935;


clrscr();


cout<<”value of a=”<

cout<<”value of b=”<

getch();


}


Output of the Programme


value of a =31946


value of b=2601

Read Count: 3 times

Comments

No comments yet.

Leave a Comment