为什么cout<< main;打印1? [英] Why cout<<main; prints 1?

查看:64
本文介绍了为什么cout<< main;打印1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 cout<< main; 为什么在我的计算机上打印 1 ?我以为它将打印main的地址.但是当我使用 printf(%x",main); 时,会得到不同的输出.

Why does cout<<main; printing 1 on my computer? I thought it would print the address of main. But when I use printf("%x",main); I get different output.

我尝试了 std :: cout 来实现其他功能.在每种情况下,我都会得到 1 .

I tried std::cout for other functions. I'm getting 1 for every case.

推荐答案

这只是未定义的行为.这是行为不可预测的代码示例.

It is nothing but undefined behavior. It is an example of a code whose behavior is unpredictable.

这篇关于为什么cout&lt;&lt; main;打印1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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