I ran the following code in codeblocks and got the output:
10 20
10 20
int main()
{
int i=10,j=20;
printf("%d %d\n",i,j);
printf("%d %d",i);
return 0;
}
What is the reason of second 20 ?
Since you're calling printf
a second time with no intervening code, the value of j
is still on the stack, left from the previous call.
Of course, you shouldn't depend on this behavior. Just because you don't see the bug doesn't mean it's not there. :-)
超出vararg列表末尾的读取是未定义的行为,因此第二个20的原因纯属偶然:您的代码可以打印任何整数,甚至崩溃。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.