比如下面的例子:
#include <stdio.h>
int main(void)
{
unsigned char i, j, k1, k2, k3 ;
//逗号,运算符
i = 15, j = 19;
k1 = (12, 23, i, j); //将12,23,i,j分别赋值给k1,最后一个是j
printf("k1 = %d\n", k1);
printf("\n");
//增1运算符
k2 = i++; //k2=15, i=16 先赋值后加
k3 = ++j; //k3=20, j=20 先加后赋值
printf("i = %d k2 = %d\n", i, k2);
printf("j = %d k3 = %d\n", j, k3);
printf("\n");
//赋值运算符
printf("赋值前:i=%d j=%d k1=%d k2=%d k3=%d\n", i, j, k1, k2, k3);
i = j = k1 = k2 = k3; //自右向左,将k3分别赋给k2,k1,j,i
printf("赋值后:i=%d j=%d k1=%d k2=%d k3=%d\n", i, j, k1, k2, k3);
return 0;
}
结果如下:
|