+ 5

[SOLVED] Please, could you explain how the answer is 35 in this code lines? I think, it must be 42. (6*7)

int a = 5, b, c; b = (a++); c = (++a); cout << b *c;

25th Sep 2021, 9:29 AM
mesarthim
mesarthim - avatar
5 Antworten
+ 3
b=5 //"++" after operand is post increment. post increment means value of a will increase after the current statement is evaluated. c=7
25th Sep 2021, 9:35 AM
Abhay
Abhay - avatar
+ 4
Because a++ is post increment first it will assign value of a to b then it will do increment of 1 in a
25th Sep 2021, 9:37 AM
Prerna 💞
+ 3
7*5= 35 b will be assigned 5 c will be assigned 7
25th Sep 2021, 9:36 AM
Saurabh
Saurabh - avatar
+ 2
Thanks for the comments! Abhay Saurabh Kumar Yadav Prerna 💞
25th Sep 2021, 9:39 AM
mesarthim
mesarthim - avatar
+ 2
int a=5,b,c; b=(a++); // b= 5 c=(++a); // c= 7 cout<<b*c // 5*7=35
3rd Oct 2021, 12:35 PM
Amandeep kaur
Amandeep kaur - avatar