printf的结果("%D",&安培;一) [英] Result of Printf ("%d", &a)

查看:205
本文介绍了printf的结果("%D",&安培;一)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C code。

    int a; 
    a =10;
    printf ("%d", &a); 

我想知道一些垃圾将被打印或错误味精将被显示。
基本上,我感兴趣的是知道如何printf的作品。是否有一个表样的东西变量列表。如果一个表有从那里将采取与放大器的价值;一个

I want to know if some garbage will be printed or error msg will be shown. Basically I am interested in knowing how printf works. Does it have a list of variables in a table sort of things. If a table is there from where it will take the value of &a

推荐答案

这是不确定的行为

如果你是新的C,这可能是一个惊喜。然而,C规范定义了某些程序的行为(称为正确的程序)。如果你不遵守规则的规范,那么你的程序是不正确的,从字面上任何可能发生。上面的链接进入更多的细节。

If you are new to C, this may be a surprise. However the C specification defines the behaviour of certain programs (called "correct programs"). If you do not follow the rules in the specification, then your program is not correct, and literally anything may happen. The above link goes into more detail.

您程序不遵守规则,因为%d个的printf 格式说明必须有相应的参数,类型 INT (在默认参数促销),而是你通过类型的参数为int *

Your program doesn't follow the rules because the %d format specifier for printf must have a corresponding argument of type int (after the default argument promotions), but instead you pass an argument of type int *.

既然是不确定的行为,输出是没有意义的,它通常是不值得进行调查。

Since it is undefined behaviour, the output is meaningless and it is generally not worthwhile to investigate.

这篇关于printf的结果("%D",&安培;一)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆