In a program which adds two numbers of integer data type and prints the result, numbers greater than 32767 can neither be given as input nor obtained as output.
for eg:
if the operends are a and b and the result is c
neither a nor b nor c can be greater than 32767.now look at the below program
#include<iostream.h>
void main()
{
int a,b;
long int c;
cin>>a;
cin>>b;
c=a+b;
cout<<c;
}
while the program is executed, I give 32767 for a
and 1 for b.. I know the result is 32768 and since its greater than 32767,it can be stored in c(if c is of integer data type)...but in the above program c is of long int data type which means it has enough and more space to accomodate 32768. Yet the result is -32768...why?
thanks in anticipation.