What is the difference between the potential increase (++i) and the posterior increase (i++) in C? Which of the two should I use when I go around the for door?
c for-loop post-increment pre-increment
The potential increase ++i
returns the increased value after increasing the value of i by 1.
int main() {
int i = 1;
int j = ++i;
printf("i:%d, j:%d", i, j);
}
Output: i:2, j:2
Rear increase i++
returns the value before increasing after increasing the value of i by 1.
int main() {
int i = 1;
int j = i++;
printf("i:%d, j:%d", i, j);
}
Output: i:2, j:1
There is a guideline to use ++i
rather than i++
There's nothing set for writing "only this."
© 2024 OneMinuteCode. All rights reserved.