+ 4
Please someone expain me how this happens. 😊
int p=8; cout <<p++; cout << ++p; //output 810
8 Respuestas
+ 13
cout << p++;
// The value of p is used, before incrementing
// 8 is printed
// then value of p becomes 9
cout << ++p;
// the value of p is incremented, and then used
// value of p becomes 10
// 10 is printed
// 810
+ 6
you have to understand prefix and postfix
https://www.sololearn.com/discuss/452566/?ref=app
https://www.sololearn.com/discuss/452566/?ref=app
https://www.sololearn.com/discuss/427611/?ref=app
+ 6
1)cout << p++ will display the output of p first and then increase the value of p by 1
so now value of p is 9..and output is 8
2)cout << ++p will increase the value of p first and then then it will display output...so here value of p will be 9+1=10...
considering both the steps...the output will show you 810...
+ 5
@Hatsy Thank you very much. 😊😊😊😊
+ 4
@chirag thank you. yeah. I have some doubts with them.
+ 4
@Prahar thank you😊
+ 4
@pratik thank you👌
+ 1
p++ is prefix. means it print the value of p first and than increment tha value of p. so as shown in your output it print 8 first and than it increment. so now p=9.
and in next line of code ++p is post fix so it increment the value of p and than print. so value of p is 9 which increment first and than print so as shown in your output is 10 after 8.
8 and 10.