0

Why y is not increase by 1 from X value?

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

4th Apr 2021, 12:03 PM
Renato Elezi
Renato Elezi - avatar
2 odpowiedzi
+ 4
Because variable "x" is being post incremented there, which means first the value of "x" would be assigned to "y" and then increment of "x" will take place. If you want "y" to be assigned after incrementing the value of "x" then you can use pre-increment operation like this " y = ++x " if you want more detailed difference between x++ and ++x then I would recommend using search bar for the same.
4th Apr 2021, 12:07 PM
Arsenic
Arsenic - avatar
+ 1
Thanks bro!!I got it!!
4th Apr 2021, 12:10 PM
Renato Elezi
Renato Elezi - avatar