Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

function returning a reference [duplicate]

$
0
0

I am a bit puzzled about why one can safely write

getValue() = 5;

in the below. The left hand side is a function. Why can we set that to 5? 

int& getValue() {  static int value = 10;  return value;}int main() {  std::cout << getValue() << std::endl;  getValue() = 5;  std::cout << getValue() << std::endl;}

This will return:

105

Viewing all articles
Browse latest Browse all 207

Trending Articles