+ 1
how the answer become 15... any one can please explane in easy way. regards #include <iostream> using namespace std; int main() { int a = 2; int b= 1; cout<<(++a/b++)*5;
4 Réponses
+ 4
if we where to break this down it might make more sense. say we have this:
int a = 2;
cout << ++a<<endl;
cout << a << endl;
this will give us :
3
3
the reason for this is the ++ is used prefix which adds +1 to a. the increment happens BEFORE the variable is called.
however, let's look at this:
int b =1;
cout <<b++<endl;
cout << b <<endl;
this will give us:
1
2
the reason for this is our first cout statement b is called BEFORE the increment. so b will be incremented however it will only be visible after that statement has finished. so putting it back together :
cout << (++a/b++) * 5; is the same as
cout << (a+1/b) * 5 for just that line
+ 2
++a = 3, because the plus signs are in front of the variable. That means, that you first increment a by 1, before you start to calculate with it.
b++ = 1, because the increment is done, after you use b in your calculation
That means "cout<<(3/1)*5"
+ 1
got it bro thank you.
+ 1
thank you dear.