C语言运算符(位运算符)+(赋值运算符)
实列
1 #include <stdio.h> 2 3 int main() 4 { 5 6 unsigned int a = 60; /* 60 = 0011 1100 */ 7 unsigned int b = 13; /* 13 = 0000 1101 */ 8 int c = 0; 9 10 c = a & b; /* 12 = 0000 1100 */ 11 printf("Line 1 - c 的值是 %d\n", c ); 12 13 c = a | b; /* 61 = 0011 1101 */ 14 printf("Line 2 - c 的值是 %d\n", c ); 15 16 c = a ^ b; /* 49 = 0011 0001 */ 17 printf("Line 3 - c 的值是 %d\n", c ); 18 19 c = ~a; /*-61 = 1100 0011 */ 20 printf("Line 4 - c 的值是 %d\n", c ); 21 22 c = a << 2; /* 240 = 1111 0000 */ 23 printf("Line 5 - c 的值是 %d\n", c ); 24 25 c = a >> 2; /* 15 = 0000 1111 */ 26 printf("Line 6 - c 的值是 %d\n", c ); 27 }
实列
1 #include <stdio.h> 2 3 int main() 4 { 5 int a = 21; 6 int c ; 7 8 c = a; 9 printf("Line 1 - = 运算符实例,c 的值 = %d\n", c ); 10 11 c += a; 12 printf("Line 2 - += 运算符实例,c 的值 = %d\n", c ); 13 14 c -= a; 15 printf("Line 3 - -= 运算符实例,c 的值 = %d\n", c ); 16 17 c *= a; 18 printf("Line 4 - *= 运算符实例,c 的值 = %d\n", c ); 19 20 c /= a; 21 printf("Line 5 - /= 运算符实例,c 的值 = %d\n", c ); 22 23 c = 200; 24 c %= a; 25 printf("Line 6 - %%= 运算符实例,c 的值 = %d\n", c ); 26 27 c <<= 2; 28 printf("Line 7 - <<= 运算符实例,c 的值 = %d\n", c ); 29 30 c >>= 2; 31 printf("Line 8 - >>= 运算符实例,c 的值 = %d\n", c ); 32 33 c &= 2; 34 printf("Line 9 - &= 运算符实例,c 的值 = %d\n", c ); 35 36 c ^= 2; 37 printf("Line 10 - ^= 运算符实例,c 的值 = %d\n", c ); 38 39 c |= 2; 40 printf("Line 11 - |= 运算符实例,c 的值 = %d\n", c ); 41 42 }
本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15070397.html