开发者

printf weird issue with two unsigned long int

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

unsigned long int tmp,final
final=1231123123123213
t开发者_开发技巧mp=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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜