日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

--c语言运算符_C按位运算符-能力问题和解答

發布時間:2025/3/11 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 --c语言运算符_C按位运算符-能力问题和解答 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

--c語言運算符

C programming Bitwise Operators Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Bitwise Operators like Bitwise OR (|), Bitwise AND (&), Bitwise NOT (!).

C編程按位運算符的天賦問題和答案:在本節中,您將找到按位運算符(如按位OR(|),按位與(&),按位NOT(!))上的C適度問題和答案。

1) Which is not a bitwise operator?

1)哪個不是按位運算符?

  • &

  • |

    |

  • <<

    <<

  • &&

    &&

  • Answer & Explanation 答案與解釋

    Correct answer: 4
    &&

    正確答案:4
    &&

    && is not a bitwise operator. It is a Logical AND operator, which is used to check set of conditions (more than one condition) together, if all conditions are true it will return 1 else it will return 0.

    &&不是按位運算符。 這是一個邏輯AND運算符 ,用于一起檢查一組條件(多個條件),如果所有條件都為true,則將返回1,否則將返回0。

    2) Predict the output of following program.

    2)預測以下程序的輸出。

    #include <stdio.h>int main() {int a=10;int b=2;int c;c=(a & b);printf("c= %d",c);return 0; }
  • c= 12

    c = 12

  • c= 10

    c = 10

  • c= 2

    c = 2

  • c= 0

    c = 0

  • Answer & Explanation 答案與解釋

    Correct answer: 3
    c= 2

    正確答案:3
    c = 2

    Bitwise AND (&), It does AND on every bits of two numbers. The result of AND is 1 only if both bits are 1.

    按位與( & ),它對兩個數字的每個位執行與。 僅當兩個位均為1時,AND的結果才為1。

    a=10 //0000 1010b=2 //0000 0010Doing bitwise AND0000 0010// 2

    For details on bitwise operator refer to Bitwise Operators and their working with Examples in C

    有關按位運算符的詳細信息,請參閱按位運算符及其在C中的示例工作

    3) Predict the output of following program.

    3)預測以下程序的輸出。

    #include <stdio.h>#define MOBILE 0x01 #define LAPPY 0x02int main() {unsigned char item=0x00;item |=MOBILE;item |=LAPPY;printf("I have purchased ...:");if(item & MOBILE){printf("Mobile, ");}if(item & LAPPY){printf("Lappy");}return 1; }
  • I have purchased ...:

    我已購買...:

  • I have purchased ...:Mobile, Lappy

    我已購買...:手機,Lappy

  • I have purchased ...:Mobile,

    我已購買...:手機,

  • I have purchased ...:Lappy

    我已購買...:藍寶

  • Answer & Explanation 答案與解釋

    Correct answer: 2
    I have purchased ...:Mobile, Lappy

    正確答案:2
    我已購買...:手機,Lappy

    Bitwise OR (|) operator copies bit(s), if they are exist either side of the operands (that means if any bit is exist in any operand). Here, binary of Macro MOBILE (0x01) is "0001" and binary of Macro LAPPY (0x02) is "0010", then result of the expression item |=MOBILE; will be "0001" and second expression item |=LAPPY; will return "0011". Thus, both conditions (item & MOBILE) and (item & LAPPY) will be true.

    如果位存在于操作數的任一側(即任何操作數中是否存在任何位), 則按位OR ( | )運算符將復制位。 此處,宏MOBILE (0x01)的二進制為“ 0001” ,宏LAPPY (0x02)的二進制為“ 0010” ,則表達式項的結果| = MOBILE; 將為“ 0001” ,第二個表達式項| = LAPPY; 將返回“ 0011” 。 因此, (item和MOBILE)條件和(item&LAPPY)條件都將成立。

    .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

    4) Predict the output of following program.

    4)預測以下程序的輸出。

    #include <stdio.h>int main() {char var=0x04;var = var | 0x04;printf("%d,",var);var |= 0x01;printf("%d",var);return 0; }
  • 8,9

    8,9

  • 4,5

    4,5

  • 8,8

    8,8

  • 4,4

    4,4

  • Answer & Explanation 答案與解釋

    Correct answer: 2
    4,5

    正確答案:2
    4,5

    Value of var is 0x04 (0100), Consider the expression var = var | 0x04 The OR (|) of 0100, 0100 is 0100, hence value will remain 0100. After the expression var |=0x01, value will be 0101 that is 0x05.

    var的值為0x04(0100) ,請考慮表達式var = var | 0x04 0100的OR(|) ,0100是0100,因此值將保持為0100。在表達式var | = 0x01之后 ,值將是0101,即0x05。

    5) Predict the output of following program.

    5)預測以下程序的輸出。

    #include <stdio.h>int main() {char flag=0x0f;flag &= ~0x02;printf("%d",flag);return 0; }
  • 13

    13

  • d

    d

  • 22

    22

  • 10

    10

  • Answer & Explanation 答案與解釋

    Correct answer: 1
    13

    正確答案:1
    13

    Consider the expression:

    考慮以下表達式:

    flag = 0x0f //0000 1111flag &= ~0x02flag = flag & (~0x02) //since ~ has precedence over ‘&’ operator0x02 = 0000 0010~0x02 = 1111 1101flag & ~0x02= 0000 1111 & 1111 1101= 0000 1101= 0x0D

    But since the placeholder in printf is %d, it prints the decimal value 13.

    但是由于printf中的占位符為%d ,因此它將輸出十進制值13 。

    6) Consider the given statement:

    6)考慮給定的陳述:

    int x = 10 ^ 2

    What will be the value of x?

    x的值是多少?

  • 5

    5

  • 6

    6

  • 7

    7

  • 8

    8

  • Answer & Explanation 答案與解釋

    Correct answer: 4
    8

    正確答案:4
    8

    XOR operator (^) copies bit(s), if one operand has 1 and other has 0, consider the given truth table:

    XOR運算符( ^ )復制一個或多個位,如果一個操作數為1,另一個操作數為0,則考慮給定的真值表:

    a b (a^b) _______________________0 0 0 0 1 1 1 0 1 1 1 0

    Here, binary of 10 is "1010" and binary of 2 is "0010", then the result of statement (10 ^ 2) will be "1000", which is equivalent to 8 in decimal.

    在這里,二進制10為“ 1010” ,二進制2為“ 0010” ,則語句(10 ^ 2)的結果為“ 1000” ,相當于十進制的8 。

    .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

    7) Predict the output of following program.

    7)預測以下程序的輸出。

    #include <stdio.h>int main() {int x=10;x &= ~2;printf("x= %d",x);return 0; }
  • x= 10

    x = 10

  • x= 8

    x = 8

  • x= 12

    x = 12

  • x= 0

    x = 0

  • Answer & Explanation 答案與解釋

    Correct answer: 2
    x= 8

    正確答案:2
    x = 8

    Consider the explanation:

    考慮以下解釋:

    x =10//0000 1010x &= ~2x = x & (~2) //since ~ has precedence over ‘&’ operator2 = 0000 0010~2 = 1111 1101x & ~0x02= 0000 1010& 1111 1101= 0000 1000= 8

    The statement x &= ~2; will clear second bit from the value of 10, binary of x is "1010" and the binary of 2 is "0010", thus this statement will clear second bit and returns "1000" that is equivalent to 8 in Decimal.

    語句x&=?2; 將從值10清除第二個位, x的二進制為“ 1010” , 2的二進制為“ 0010” ,因此此語句將清除第二個位并返回與十進制中的8等效的“ 1000” 。

    8) Which Bitwise Operator can be used to check whether a number is EVEN or ODD quickly?

    8)哪個位運算符可用于快速檢查數字是偶數還是奇數?

  • Bitwise AND (&)

    按位與(&)

  • Bitwise OR (|)

    按位或(|)

  • Bitwise XOR (^)

    按位XOR(^)

  • Bitwise NOT (~)

    按位非(?)

  • Answer & Explanation 答案與解釋

    Correct answer: 1
    Bitwise AND (&)

    正確答案:1
    按位與(&)

    Bitwise AND (&) Operator can be used to check whether a number if EVEN or ODD, consider the statement (num & 1), this statement will return 1 if first bit of the number is High (1) else it will return 0. All ODD numbers have their firs bit 1 and ODD numbers have 0.

    可以使用按位AND(&)運算符來檢查一個數字是偶數還是奇數,請考慮語句(num&1) ,如果數字的第一位為High(1),則此語句將返回1,否則將返回0。所有ODD編號的第一個比特為1,而ODD編號的第一個比特為0。

    Consider the following program:

    考慮以下程序:

    #include <stdio.h>int main() {int count;for(count=1; count<=10; count+=1)if(count & 1)printf("%2d is ODD number\n",count);elseprintf("%2d is EVEN number\n",count);return 0; }

    Output

    輸出量

    1 is ODD number2 is EVEN number3 is ODD number4 is EVEN number5 is ODD number6 is EVEN number7 is ODD number8 is EVEN number9 is ODD number 10 is EVEN number

    9) Which statement is suitable to check 3rd (count from 0) bit is high (set) or not?

    9),該語句是合適的,以檢查第三 ( 從0)位計數是高 (組)或不?

  • (num & (1<<3))

    (數字&(1 << 3))

  • (num & 0x08)

    (數字和0x08)

  • (num & 0x03)

    (數字和0x03)

  • Both (1) and (2)

    (1)和(2)

  • Answer & Explanation 答案與解釋

    Correct answer: 4
    Both (1) and (2)

    正確答案:4
    (1)和(2)

    The value of (1<<3) is 8 in Decimal and value of 0x08 is 8 in Decimal, both statements are suitable to check whether 3rd bit of num is High (set) or not.

    (1 << 3)的值為8和十進制的0x08的值在十進制8,這兩個語句適合于檢查NUM的第三位是否為高(組)或沒有。

    Consider this program:

    考慮以下程序:

    #include <stdio.h>int main() {int num;printf("Enter an integer number: ");scanf("%d",&num);if(num & (1<<3))printf("3rd bit is High (Set)\n");elseprintf("3rd bit is Low\n");return 0; }

    Output

    輸出量

    First run: Enter an integer number: 15 3rd bit is High (Set) Second run: Enter an integer number: 7 3rd bit is Low

    Binary of 15 is: 1111 & Binary of 7 is: 0111, thus in first case 3rd bit is high and in second case 3rd bit is low. [Count from 0]

    的15二進制是:1111的7個二進制是:0111,從而在第一種情況下第三位為高,在第二種情況下第三位為低。 [從0開始計數]

    10) Left shift (<>) operators are equivalent to _____________ by 2.

    10)左移(<>)運算符等于_____________ 2。

    Choose the correct words...

    選擇正確的單詞...

  • Multiplication and Division

    乘法與除法

  • Division and Multiplication

    除法與乘法

  • Multiplication and Remainder

    乘法與余數

  • Remainder and Multiplication

    余數與乘法

  • Answer & Explanation 答案與解釋

    Correct answer: 1
    Multiplication and Division

    正確答案:1
    乘法與除法

    Left shift by 1 return the multiplication by 2 and Right shift by 1 return the division by 2.

    左移1返回乘以2,右移1返回除以2。

    Consider this program:

    考慮以下程序:

    #include <stdio.h>int main() {int num;printf("Enter an integer number: ");scanf("%d",&num);printf("Multiplication by 2 = %d\n", (num<<1));printf("Division by 2 = %d\n",(num>>1));return 0; }

    Output

    輸出量

    Enter an integer number: 100 Multiplication by 2 = 200 Division by 2 = 50

    翻譯自: https://www.includehelp.com/c/bitwise-operators-aptitude-questions-and-answers.aspx

    --c語言運算符

    總結

    以上是生活随笔為你收集整理的--c语言运算符_C按位运算符-能力问题和解答的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 青娱乐在线免费视频 | 天天爱天天做 | 国产一级片播放 | 广州毛片 | 西野翔之公侵犯中文字幕 | 免费涩涩视频 | 精品久久久无码中文字幕边打电话 | 黄色网址免费 | 波多野结衣1区 | 国产情侣第一页 | 影音先锋每日资源 | 一区二区三区精彩视频 | 一级作爱视频 | 成人77777 | 在线免费观看亚洲 | 欧美做爰猛烈床戏大尺度 | 国产精品自产拍 | 少妇aaaa| 999热 | 亚洲夜色| 狠狠做深爱婷婷综合一区 | 国产大片中文字幕在线观看 | 午夜精品欧美 | 成人自拍网 | 中文字幕成人 | 同性色老头性xxxx老头 | www.555国产精品免费 | 国产成人自拍网 | 91成人毛片 | 插插看| 日韩精品在线视频观看 | 亚洲一二三四 | 一区二区三区有限公司 | 无码人妻精品丰满熟人区 | 男生操女生屁股 | www.555国产精品免费 | 欧美午夜一区 | 超碰在线综合 | 一区二区三区精品久久久 | 亚洲欧美天堂 | 秋霞福利片 | 激情宗合 | 一本到av| 国产精品一区二区免费视频 | 国产欧美日韩综合精品一区二区三区 | 欧美猛交免费 | 国精产品一区二区 | 99精品人妻无码专区在线视频区 | 青青草国产在线播放 | 懂色av一区 | 久久久久久欧美精品se一二三四 | 熟女俱乐部五十路六十路av | 麻豆国产精品一区 | 玩日本老头很兴奋xxxx | 国产精品视频在 | 国产精品久久AV无码 | 成人精品网址 | 亚洲精选一区二区 | 中文字幕在线观看网址 | 色先锋av资源 | 日日鲁鲁鲁夜夜爽爽狠狠视频97 | 国产乱视频 | 亚洲草逼| 青青草网址 | 日韩毛片av| 交视频在线播放 | 色老大影院 | 国产成人精品在线 | 久久久福利 | 古装做爰无遮挡三级 | 91青青草 | 国产一卡二卡三卡 | 日韩人妻精品中文字幕 | 天天爽天天爽 | 99久久久无码国产精品性 | 亚洲视频黄 | 丝袜中文字幕 | 自拍偷拍色 | 午夜肉伦伦影院 | 欧美激情视频一区二区三区 | av色站| 日本美女动态 | caopeng视频| 黄色第一网站 | 悠悠色在线 | 亚洲天堂网站在线 | 欧美黑人xxxⅹ高潮交 | 在线观看成人一区 | 狂野欧美性猛交免费视频 | 亚洲一区精品视频在线观看 | 撒尿free性hd| 日韩欧美二区 | 爱情岛亚洲论坛入口 | 国产视频xxxx | 日本电影一区 | 99看片| 邵氏电影《金莲外传2》免费观看 | 韩国一区二区在线播放 | 亚洲一区在线不卡 |