收录日期:2020/10/28 07:20:53 时间:2010-09-07 01:44:57 标签:c,printf

i have this code (im working with big files support in ansi c)

unsigned long int tmp,final
final=1231123123123213
tmp=final;
    printf("%llu %llu  \n",final,tmp);
    printf("%llu  \n ",tmp);

it prints

1231123123123213 0
1231123123123213

i dont get it

Format specifier used with unsigned long int is %lu. You are using %llu, which is format specifier for unsigned long long int. The behavior of your code is undefined.

You need to decide what it is you are trying to do. Either use the correct format specifier (to match the type), or use the right type (to match the format specifier).

Because you're using the wrong type.

unsigned long long int tmp, final;

The compiler should complain about the numeric constant (the literal 1231123123123213) not fitting a long int. It gets truncated. Plus, %llu is for printing long long ints, not long ints ;).

You need %lu not %llu.