#include<stdio.h>
int main()
{
long long var;
scanf("%lld",&var);
printf("%lld",var);
return 0;
}
/* When I enter 16 digit number for above code its working*/
========================================
But I am not sure why below code is not showing correct value
#include<stdio.h>
int main()
{
long long var=1234567890123456;
printf("%lld",var);
return 0;
}
Please Help?
As @rici points out, the problem is with the var
assignment.
// long long var=1234567890123456;
long long var=1234567890123456LL; // append LL
printf("%lld",var);
1234567890123456
was too large for int
and unsigned
in OP environment. To specify higher values, use the desire suffix.
I suspect 1015724736
was printed out by the OP originally as 1234567890123456 % 4294967296. 4294967296 being the assumed range of of OP's unsigned
( 0 to 4294967295).