(資料圖片僅供參考)
+-*/++--% -- 取余
# include int main(){ int a = 15,b = 8,c; c = a + b; printf("c = %d\n",c); c = a - b; printf("c = %d\n",c); c = a * b; printf("c = %d\n",c); c = a / b; printf("c = %d\n",c); c = a % b; printf("c = %d\n",c); return 0;}
# include int main(){ float a = 15,b = 8,c; c = a + b; printf("c = %f\n",c); c = a - b; printf("c = %f\n",c); c = a * b; printf("c = %f\n",c); c = a / b; printf("c = %f\n",c); // float是不能進(jìn)行取余操作 // c = a % b; // printf("c = %f\n",c); return 0;}
> < >= <= == !==
! -- 非&& -- 邏輯與(短路與)|| -- 邏輯或(短路或)
~ -- 按位取反#include int main(){ unsigned char x = 0x17,y; y = ~x; // x:0001_0111 y = 1110_1000 e8 printf("%#x\n",y); // %#x -- x表示16進(jìn)制打印,#表示自動(dòng)補(bǔ)齊0x return 0;}
& -- 按位與 unsigned char x = 0126, y = 0xac,z;z = x & y;x 01_010_110y 1010_1100x&y 00000100 0x04
| -- 按位或unsigned char x = 076,y = 0x89,z;z = x | y;x 00111110y 10001001z 10111111
^ -- 按位異或unsigned char x = 75,y = 0173,z;z = x ^ y;
移位運(yùn)算運(yùn)算量 運(yùn)算符 表達(dá)式unsigned char a = 0xe4,b;b = a << 3;a 1110 0100b 0010 0000 -- 0x20#include int main(){ unsigned char a = 0x4,b,c,d; b = a << 1; C = a << 2; d = a << 3; printf("%#x\n",a); // a = 0000_0100 b = 0000_1000 8 printf("%#x\n",a); // 16 printf("%#x\n",a); // 32 return 0;}
+=-=/=%=...#include int main(){ int count,sum; count = 0; sum = 0; while(count++ < 20) { sum += count; } printf("sum = %d\n",sum); return 0;}
表達(dá)式1 ? 表達(dá)式2 : 表達(dá)式3int x = 82, y = 101;x >=y ? x+18:y-100x<(y-11):x-22:y-1#include int main(){ int x,y; x = 70; y = x++ > 70 ? 100 : 0; printf("x = %d y = %d\n",x,y); // 71 0 return 0;}
執(zhí)行順序是從左到右,結(jié)果由最后一個(gè)表達(dá)式?jīng)Q定float x = 10.5,y = 1.8,z = 0;z = (x +=5,y = x+0.2); //z =10.7
sizeof(數(shù)據(jù)類型)sizeof(數(shù)組)sizeof(變量名)
標(biāo)簽: