• The answer is 2) 0.
  • If you have the appropriate headers it will output 0.
  • It prints nothing because there's no endl or other flush on the cout ;-) But this is a simple question about post increment. It boils down to whether return on a post incremented variable returns before or after the increment. The answer is that m is evaluated for the expression before the increment operator applies. Since m is then a static out of scope it is irrelevant, however, if m was a global or a call by ref it would be incremented and the pre increment value returned. So a slightly more interesting example is: int v(int &m) { return m++; } int main() { int m = 0; cout<<v(m)<<m; }
  • m++ means read then increment ++m increment then read. Thus the result is zero.

Copyright 2020, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy