0
What does num++ mean?
Whats the purpose of it? And will I use it when i code in the future (eg. Software, games and etc.)
3 Respostas
+ 2
it's a shortcut to increase "num" by 1. It's the same as:
num=num+1
And, yes, you will use this all the time
+ 1
In addition to previous answer, there is a subtle difference between ++num and num++.
If you use them as statements on their own, as in:
num++;
--vs--
++num;
The result is the same i.e. num is incremented by 1.
But if you use them in an assignment expression, they have a subtle difference:
int num = 3;
int y = num++;
//y is 3 here since num is 'post'-assignment incremented.
int num = 3;
int y = ++num;
//y is 4 here since nume is 'pre'-assignment incremented.
0
postfix mean it return the value first then incremental by 1. e.g. int num = 1; int x = num++; the value of x will be 1 then incremental the value of num by 1 to 2.