<strong id="ctjbx"></strong>

  1. <strong id="ctjbx"></strong>
    <ruby id="ctjbx"></ruby>

    每日快報!03-運算符

    來(lái)源:博客園時(shí)間:2023-05-17 06:25:53


    (資料圖片僅供參考)

    1.運算符

    1.1 算術(shù)運算符

    +-*/++--% -- 取余
    # 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;}

    1.2 關(guān)系運算符

    > < >= <=  == !==
    • 通常是用在條件判斷中

    1.3 邏輯運算符

    ! -- 非&& -- 邏輯與(短路與)|| -- 邏輯或(短路或)

    1.4 位運算

    ~ -- 按位取反#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)補齊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;
    移位運算運算量 運算符 表達式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;}
    • 左移一位,擴大兩倍

    1.5 復合賦值運算符

    +=-=/=%=...#include int main(){  int count,sum;  count = 0;  sum = 0;  while(count++ < 20) {    sum += count;  }  printf("sum = %d\n",sum);  return 0;}

    1.5 三目運算符

    表達式1 ? 表達式2 : 表達式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;}

    1.7 逗號運算符

    執行順序是從左到右,結果由最后一個(gè)表達式?jīng)Q定float x = 10.5,y = 1.8,z = 0;z = (x +=5,y = x+0.2);  //z =10.7

    1.8 sizeof運算符

    sizeof(數據類(lèi)型)sizeof(數組)sizeof(變量名)

    1.9 運算符的優(yōu)先級

    標簽:

    責任編輯:FD31
    上一篇:nh4cl的電子式怎么寫(xiě)_nh4cl的電子式|重點(diǎn)聚焦
    下一篇:最后一頁(yè)

    精彩圖集(熱圖)

    熱點(diǎn)圖集

    最近更新

    信用中國

    • 信用信息
    • 行政許可和行政處罰
    • 網(wǎng)站文章

    久爱免费观看在线精品_亚洲综合一区二区三区_最新国产国模无码视频在线_中文字幕无码精品亚洲资源网久久

      <strong id="ctjbx"></strong>

    1. <strong id="ctjbx"></strong>
      <ruby id="ctjbx"></ruby>