Use variables and operaters in output(cout) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Use variables and operaters in output(cout)

I wrote two programs the first one is ok but the second one doesn't run. Can't we use operaters and variables in cout without adding a new variable for the result? There is no space between minus minus . #include <iostream> using namespace std; int main() { int a=5,b=3,c; c=++a/b- -+3%12; cout<<c; return 0; #include<iostream> using namespace std; int main() { int a=5,b=3; cout<<++a/b- -+3%12; } And also can you help me why" b - - " doesn't effect the result , is it just for the next line?

3rd Nov 2019, 8:22 AM
Armina
Armina - avatar
3 Answers
+ 1
(1) Both codes run successfully and have the same output to me. (2) b-- effects after "b--". And --b effects just before "--b". For example: int b = 5; cout << b + b-- -b; //Output 6. (5) (5) (4) cout << b + --b -b; //Output 4. (4) (3) (3)
3rd Nov 2019, 8:54 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
CarrieForle Thanks for your help so one more thing ,Without space between minus minus why doesn't run while between plus plus there is no space so there is no need to define a variable like c for result like for example like this code which doesn't run #include<iostream> using namespace std; int main() { int a=5,b=3,c; cout<<c=a - b; return 0; }
3rd Nov 2019, 10:02 AM
Armina
Armina - avatar
+ 1
Thanks Martin Taylor
3rd Nov 2019, 6:20 PM
Armina
Armina - avatar