// ++i will increment the value of i, and then return the incremented value.
i = 1;
j = ++i;
(i is 2, j is 2)
// i++ will increment the value of i, but return the original value that i held before being incremented.
i = 1;
j = i++;
(i is 2, j is 1)
i++ : Assign then increment
++i : increment then Assign
//Remember that the values are i = 10, and j = 10
i is 10
i++ is 10 //Assigns (print out), then increments
i is 11
j is 10
++j is 11 //Increments, then assigns (print out)
j is 11
#include <stdio.h>
int main() {
int i=5,j;
j=i++;
printf ("
after postfix increment i=%d j=%d", i,j);
i=5;
j=++i;
printf ("
after prefix increment i=%d j=%d",i,j);
return 0;
}
//output:
//after postfix increment i=6 j=5
// after prefix increment i=6 j=6
let x = 10;
while(x < 20) { //when x is less than 20
x++; //add 1 to x
console.log(x); //logs the numbers 11 - 20 to the console
}
int i = 10, j = 10;
printf ("i is %i
", i);
printf ("i++ is %i
", i++);
printf ("i is %i
", i);
printf ("j is %i
", j);
printf ("++j is %i
", ++j);
printf ("j is %i
", j);
Code Example |
---|
Cpp :: sort c++ stl |
Cpp :: c++20 inizialize a thread |
Cpp :: c++ constructor initializing list |
Cpp :: 28+152+28+38+114 |
Cpp :: sfml get position |
Cpp :: my cpp |
Cpp :: print an array c++ |
Cpp :: second smallest element using single loop |
Cpp :: c++ string to vector using delimiter |
Cpp :: c++ array access operator |
Cpp :: c++ read_ascii |
Cpp :: how to add 2 objects using operator overloading in c++ |
Cpp :: c++ sigabrt |
Cpp :: c++ insert vector into vector |
Cpp :: MPI_Sendrecv |
Cpp :: ala vida |
Cpp :: Initialize Vector Iterator with begin() function |
Cpp :: what is imposter syndrome |
Cpp :: def minimulHeaviestSetA(arr,n) |
Cpp :: Arduino Access Point ESP8266 |
Cpp :: vector.rbegin() |
Cpp :: how to read qlistwidget in c++ |
Cpp :: typeid to string c++ |
Cpp :: c++ to c converter online free |
Cpp :: how to declare a function in c++ header file |
Cpp :: c++ find in pair |
Cpp :: c++ cin string |
Cpp :: c vs c++ vs c# |
Cpp :: flags of open operation c++ |
C :: pi in c language |