Printing long int value in C -
i have 2 variables of long int type shown below:
long int a=-2147483648, b=-2147483648; a=a+b; printf("%d",a); i getting zero. tried changing type long long int, i'm still not getting correct answer.
you must use %ld print long int, , %lld print long long int.
note long long int guaranteed large enough store result of calculation (or, indeed, input values you're using).
you need ensure use compiler in c99-compatible mode (for example, using -std=gnu99 option gcc). because long long int type not introduced until c99; , although many compilers implement long long int in c90 mode extension, constant 2147483648 may have type of unsigned int or unsigned long in c90. if case in implementation, value of -2147483648 have unsigned type , therefore positive, , overall result not expect.
Comments
Post a Comment