Why does C++ always display a Hexadecimal memory address and not just an integer?

  addressing, c++, encapsulation, memory

I wanted to know why printing the address of a variable in c gives the output as something like 823759733
while, doing the same in c++ shows 0x7ff6474009c??
Is this the work of ‘cout’, that formats the address as a hex? or is the variable memory address cloaked to show some arbitrary address to encapsulate it??
I know that everything is going on inside virtual memory in C++, is this the same for C?

example –

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

it should print an integer.

the same code written in c++
and

cout<<ptr

it shows a hex(I want to know why?)

Source: StackOverflow C++

LEAVE A COMMENT