Saturday, May 22, 2010

Explain data type range for integers in C language?

Why am i getting this output for the following C program?





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;





int input=-2147483649;


main()


{


printf("%d",input);





getch();


}








Output:


2147,483,647

Explain data type range for integers in C language?
Dude you need to go out more .
Reply:Hi


As a previous answerer has intimated int (or long int) overflows outside of the range -2147483647 to +2147483647





Suggest you use:





double inpt = -2147483649.0;


main()


{


printf("%10.0lf\n",inpt);


}





This will give you what you want.


Regards


G
Reply:Range = -pow(2, 31) to pow(2, 31) - 1





-2147483649 is less than -pow(2, 31)


(by one actually)
Reply:because that is max limit





it is converting it to +ve number because 1 bit is used for sign (lsb or msb ? )

radiata

No comments:

Post a Comment