+ 1
what is wrong in this code
#include<iostream> using namespace std; int main() { int x=0, y=0; cout<<++(x+y); }
5 Answers
+ 3
"error: lvalue required as increment operand"
Isbah the error message tells you what is wrong. In C++ the preincrement operator can be used only on lvalues. An lvalue is any identifier that may be used on the left-hand side of an assignment operator (=, +=, -=, *=, ... etc.). You may not assign (x+y) = 1, therefore you may not use ++(x+y) as an expression.
Instead, simply add 1 with the normal addition operator, like (x+y+1), to get the equivalent result.
+ 4
Isbah
int main()
{
int x=0, y=0;
int z = (x+y);
printf("%d",++z);
}
answer: 1
+ 3
++ is a unary operator..
can be applied to only a variable. Not to any constant or block...
Just use cout << ( x+ y) ;
oh.. what are trying there actually???
0
#include <iostream>
int main()
{
int x=0,y=0;
std::cout<<++x + y++;
return 0;
}
Increment operators didn't works on literals i guess :D
0
The ++ is only accepted for a variable.