算术运算符

二元运算: +,-,*,/,%(取模或求余)

一元运算符: ++num,--num,num++,num--

int num1 = 10;

int num2= ++num1+num1--;

printf("num2=%d",num2);//22

printf("num1=%d",num1);//10

 

表达式

如何计算

结果 (num1=5)

num2 = ++num1;

num1 = num1 + 1;

num2 = num1;

num2 = 6;

num1 = 6;

num2 = num1++;

num2 = num1;

num1 = num1 + 1;

num2 = 5;

num1 = 6;

num2 = --num1;

num1 = num1 - 1;

num2 = num1;

num2 = 4;

num1 = 4;

num2 = num1--;

num2 = num1;

num1 = num1 - 1;

num2 = 5;

num1 = 4; 

通过中间变量实现变量交换:

   int num1,num2;

   int temp;//中间变量

   printf("请输入的num1的值");

   scanf("%d",&num1);

   printf("请输入的num2的值");

   scanf("%d",&num2);

   printf("交换前num1=%d,num2=%d\n",num1,num2);

   temp=num1;

   num1=num2;

   num2=temp;//通过中间变量实现交换

   printf("交换后num1=%d,num2=%d\n",num1,num2);

 

posted on 2017-03-21 01:26  我是小美女  阅读(123)  评论(0编辑  收藏  举报