「C言語」後置演算子を使うサンプル
構文
変数名–
変数名++
サンプルコード
#include <stdio.h>
int main(void){
int m = 120;
int n = 120;
int res1;
int res2;
/* 後置デクリメント演算子 */
res1 = m--;
res2 = n++;
printf("m=%d, res1=%d\n", m,res1);
printf("n=%d, res2=%d\n", n,res2);
return 0;
}
#include <stdio.h>
int main(void){
int m = 120;
int n = 120;
int res1;
int res2;
/* 後置デクリメント演算子 */
res1 = m--;
res2 = n++;
printf("m=%d, res1=%d\n", m,res1);
printf("n=%d, res2=%d\n", n,res2);
return 0;
}
#include <stdio.h> int main(void){ int m = 120; int n = 120; int res1; int res2; /* 後置デクリメント演算子 */ res1 = m--; res2 = n++; printf("m=%d, res1=%d\n", m,res1); printf("n=%d, res2=%d\n", n,res2); return 0; }
実行結果
m=119, res1=120
n=121, res2=120