Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

c++ - when we write void variable like void *p ; cout<<&p; cout<<p; so it give two different address but why?

C++ output give two different address but why complier give two address instead of I am writing only one variable

void *p ;
cout<<&p<<p;
question from:https://stackoverflow.com/questions/66046233/when-we-write-void-variable-like-void-p-coutp-coutp-so-it-give-two-dif

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

void *p ; is an uninitialized pointer. So what you will have inside the pointer there is actual garbage. When you do &p, your returning the address of the pointer p. That's why they both return different values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...