+ 2

What is the output of the following program?

int a=1; b=0; b=a cout<<++a*b++;

2nd Mar 2017, 3:17 PM
naji goz
naji goz - avatar
2 Answers
+ 9
* int a=1,b=0; b=a; (Missed ;) And the output is 2.
2nd Mar 2017, 3:43 PM
Mr.Robot
Mr.Robot - avatar
+ 2
Well first of all, for the: int a=2; b=0; You seperate each new variable with the same type by a comma instead int =2, b=0; Also the statement b=a needs a semicolon b=a; And then your code will work It will like like this at the end: #include <iostream> using namespace std; int main() { int a=1, b=0; b=a; cout<<++a*b++; } The answer will be 2 because you set b to a, which is 1, so both a and b are 1. Then you perfrmed an equation using "++." Before the variable means add one in the equation, after the variable means don't add one till after the equation, so the equation becimes 1*2 which is equal to 2. Hope this helped.
2nd Mar 2017, 3:45 PM
Rain
Rain - avatar