Alex Rivera | Logout

Why is the address of this volatile variable always at 1?

Asked 2011-11-23T08:44:05.067
26

I wanted to inspect the address of my variable

volatile int clock;
cout << &clock;

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

Edit
Report

1 Answer

23

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;
answered 2011-11-23T08:46:19.003

Your Answer