Question discussion

What is the output of the following C++ program?#include using namespace std; int main() { int x = 10; int &r = x; r++; cout

1176Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
using namespace std;
int main() {
    int x = 10;
    int &r = x;
    r++;
    cout << x << " " << r;
}
  • A10 11
  • B11 10
  • C11 11
  • D10 10
Correct answer: C

Explanation

r is an alias of x, so incrementing r increments x and both print 11.

Discussion 0

Nobody has replied yet. Start the discussion!