views:

149

answers:

3

Why in C++ the prefix return a reference but the postfix return a value?

+3  A: 

Because with prefix you modify the object and then return it (so it can be lvalue), and with postfix you return the unchanged object (i.e. a copy) and only then update it (this is of course done by first storing the copy in a temporary, updating the original object, and then returning the temporary by value.)

Nikolai N Fetissov
+1  A: 

How do you return reference to something that doesn't exist?

vava
A: 

theoretically u cant (or shouldnt) refer to non-existent but if u want to it, use wild/null pointer. its a guaranteed access violation /facepalm

YeenFei
What are you talking about?
SLaks
apparently the author changed the topic right after i replied.look at vava response you will realise he was asking for method to returning reference of non-existence object
YeenFei