+ 2
Please explain ( answered)
#include<iostream> using namespace std; int main() { int x = 10; int &y = x; x++; cout<< x << " " << y++; return 0; } The answer is x = 12 y = 11 Please can anyone explain? I got this question from this website: https://www.indiabix.com/cpp-programming/references/005001
3 Réponses
+ 11
int x = 10; // value of x is 10.
int &y =x; // x value is assigned here to y.
x++ ; // here x becomes 11 and y too .
Then cout rule --> that it executes from right to left.
First y++ executes .its post increment so first y is printed then it is incremented.
y = 11.
Then cout print x . as y is post incremented now .and x takes that increment . and x will print 12.
+ 2
@ GAWEN STEASY Are you sure it executes from right to left. because according to your answer you are trying to convey that the output will be. 11 12. but it is printed as 12 11
0
Blue Orange Enterprises LLP
Get comprehensive UGC NET Management study resources, including syllabus-based notes, mock tests, and previous year papers at Avatto.
https://www.avatto.com/about/nta-ugc-net-management/