为什么这个volatile变量的地址总是为1? [英] Why is the address of this volatile variable always at 1?

查看:157
本文介绍了为什么这个volatile变量的地址总是为1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查变量的地址

volatile int clock;
cout << &clock;

但它总是说x在地址1.我做错了什么?

But it always says that x is at address 1. Am i doing something wrong??

推荐答案

iostreams将投射大多数指针到 void * volatile 指针。因此,C ++回落到 bool 的隐式转换。如果您要打印地址,则显式地转换为 void *

iostreams will cast most pointers to void * for display - but no conversion exists for volatile pointers. As such C++ falls back to the implicit cast to bool. Cast to void* explicitly if you want to print the address:

std::cout << (void*)&clock;

这篇关于为什么这个volatile变量的地址总是为1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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