「C言語」後置演算子を使うサンプル

2020年11月23日

構文
変数名–
変数名++
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#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

C言語

Posted by arkgame