2

I am using cc compiler on AIX 6.1 (Unix)

#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?

Shrirang Kumbhar
  • 363
  • 4
  • 17

2 Answers2

0

Usually %lld works for cc. Try %I64d

Scotty Bauer
  • 1,277
  • 9
  • 14
  • Scotty, Could you please tell me what is objdump and how to objdump a C code? – Shrirang Kumbhar Aug 14 '13 at 13:06
  • @sku, What objdump does is disassembles the compiled C file from binary to assembly instruction. I asked you to obj dump it because sometimes the compiler makes assumptions about your code that you didn't mean. You can read more about objdump here: http://www.thegeekstuff.com/2012/09/objdump-examples/ – Scotty Bauer Aug 14 '13 at 14:54
0

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).

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256