如果我的电脑是 32 位系统,它有一个 32 位地址对吗?但是当我在 C 中打印任何内存地址时,为什么我会得到一个 <32 位的地址? [英] If my computer is a 32 bit system, it has a 32 bit address right? But when I print any memory address in C why do I get an address &lt;32bit?

查看:90
本文介绍了如果我的电脑是 32 位系统,它有一个 32 位地址对吗?但是当我在 C 中打印任何内存地址时,为什么我会得到一个 <32 位的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如

printf("%u",&a);

给我输出

<块引用>

65524

这是一个 16 位地址.

解决方案

因为您使用了错误的格式说明符,该说明符会调用 未定义的行为.

要打印指针,您应该使用 %p 格式说明符并将参数转换为 void*.类似的东西

 printf("%p",(void *)&a);

将完成这项工作.

也就是说,您应该首先了解虚拟内存的概念.>

For example

printf("%u",&a);

gives me output

65524

which is a 16 bit address.

解决方案

Because you used wrong format specifier which invokes undefined behavior.

To print a pointer, you should use %p format specifier and cast the argument to void*. Something like

 printf("%p",(void *)&a);

will do the job.

That said, you should look into the concepts of virtual memory the first thing.

这篇关于如果我的电脑是 32 位系统,它有一个 32 位地址对吗?但是当我在 C 中打印任何内存地址时,为什么我会得到一个 <32 位的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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