关于c ++:printf和scanf中%lli和%lld之间的区别?

Difference between %lli and %lld in printf and scanf?

本问题已经有最佳答案,请猛点这里访问。

我和我的朋友在争论%lli%lld。 我通常使用%lli,并且每次他争辩要在printfscanf中使用%lld。 他声称%lli%lld是不同的。

GNU GCC编译器中的%lli%lld格式说明符之间是否有区别,或者它们相同吗?


对于printf,它们完全相同。

http://en.cppreference.com/w/cpp/io/c/fprintf

d, i converts a signed integer into decimal representation [-]dddd.

Precision specifies the minimum number of digits to appear. The default precision is 1.
If both the converted value and the precision are ?0? the conversion results in no characters.

对于scanf,它们是不同的。 以下是来自文档的引用。

d matches a decimal integer.
The format of the number is the same as expected by strtol() with the value 10 for the base argument

i matches an integer.
The format of the number is the same as expected by strtol() with the value ?0? for the base argument (base is determined by the first characters parsed)

对于i,如果您的数字以0开头,它将被解析为八进制。

http://en.cppreference.com/w/cpp/io/c/fscanf


可能您应该看到文档...?

对于printf(),它们是等效的,但是对于scanf(),它们是不同的。

http://www.cplusplus.com/reference/cstdio/scanf/

对于说明符d,从输入流中提取的字符是任意数量的十进制数字(0-9),可以选择在其后加上一个符号(+或-)。

对于i,它是任意数量的数字,可以选择在其后加上一个符号(+或-)。
默认情况下假设使用十进制数字(0-9),但是0前缀将引入八进制数字(0-7)和0x十六进制数字(0-f)。
签名的论点。