+ 1

Why the output of this code is 9 not 10? Plz explain 🙏

#include <iostream> using namespace std; int main() { int a=9; { int a=9; a++; } cout<<a++; return 0; }

18th Oct 2021, 2:35 PM
Jainil Raval
Jainil Raval - avatar
3 Réponses
+ 3
scope. The second a belongs to a inner block code and a++ increments the a in its scope
18th Oct 2021, 2:38 PM
arturop200
arturop200 - avatar
+ 1
Arturop Got it Thanks for explaining 🙏
18th Oct 2021, 3:19 PM
Jainil Raval
Jainil Raval - avatar
0
Because you use post-increment operator when you send output of <a>. Had you used pre-increment operator, you'll get 10 cout << ++a; // output 10
18th Oct 2021, 2:46 PM
Ipang