+ 1
Find the output.
#include<iostream.h> int main() { int x = 80; int &y = x; x++; cout << x << " " << --y; return 0; }
1 Resposta
+ 2
Your code will output an error, due to not referencing the std namespace at all for cout and possibly for your include statement which depends on which compiler you are using.
Otherwise, once those issues are fixed it should output:
80 80
depending on your compiler.
Both x and y point to the same address in memory and are therefore the exact same variable. The line x++ increments both x and y to 81. Then in your cout --y decrements both x and y back to 80 which is then output. This may vary depending on which compiler is being used and its particular operator precedence, but the code below will output as described in the codeplayground.
#include <iostream>
using namespace std;
int main()
{
int x = 80;
int &y = x;
x++;
cout << x << " " << --y;
return 0;
}