+ 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?
4 Respostas
+ 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)
+ 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;
}
+ 1
Thanks Martin Taylor