自增自减运算符
i++ ,i--
运算符在后,在表达式中先用i 的值,下条语句i 的值自增或者自减
#include <stdio.h>
int main()
{
int i=1;
int num;
num=i++;
printf("num=%d,i=%d\n",num,i);//num=1 ,i=2
return 0;
}
++i 先加,后用
#include <stdio.h>
int main()
{
int i=1;
int num;
num=++i;
printf("num=%d,i=%d\n",num,i);//num=2,i=2
return 0;
}
#include <stdio.h>
int main(int argc, char *argv[])
{
int i=1;
int num;
num = (i++)+(i++)+(i++);// 1 2 3
printf("num=%d\n",num);//num为6
return 0;
}
练习:试着算算num的值为多少
#include <stdio.h>
int main(int argc, char *argv[])
{
int i=1;
int num;
num = (++i)+(++i)+(++i);
printf("num=%d\n",num);
return 0;
}
标签:return,--,++,C语言,运算符,int,num,printf,main
From: https://blog.csdn.net/qq_57464528/article/details/141530569