>1, 32>>0); printf("%d "> >1, 32>>0); printf("%d ">
logo

CuriousTab

CuriousTab

Discussion


Home C Programming Bitwise Operators Comments

  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        printf("%d %d\n", 32<<1, 32<<0);
        printf("%d %d\n", 32<<-1, 32<<-0);
        printf("%d %d\n", 32>>1, 32>>0);
        printf("%d %d\n", 32>>-1, 32>>-0);
        return 0;
    }
    


  • Options
  • A. Garbage values
  • B. 64 32
    0 32
    16 32
    0 32
  • C. All zeros
  • D. 8 0
    0 0
    32 0
    0 16

  • Correct Answer
  • 64 32
    0 32
    16 32
    0 32 


  • Bitwise Operators problems


    Search Results


    • 1. What will be the output of the program?
      #define P printf("%d\n", -1^~0);
      #define M(P) int main()\
                   {\
                      P\
                      return 0;\
                   }
      M(P)
      

    • Options
    • A. 1
    • B. 0
    • C. -1
    • D. 2
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
          return 0;
      }
      

    • Options
    • A. 4 1 8 1
    • B. 4 >> 1 8 >> 1
    • C. 2 >> 4 Garbage value >> Garbage value
    • D. 2 4
    • Discuss
    • 3. If an unsigned int is 2 bytes wide then, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          unsigned int m = 32;
          printf("%x\n", ~m);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. 0000
    • C. ffdf
    • D. ddfd
    • Discuss
    • 4. If an unsigned int is 2 bytes wide then, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          unsigned int a=0xffff;
          ~a;
          printf("%x\n", a);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. 0000
    • C. 00ff
    • D. ddfd
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i=32, j=0x20, k, l, m;
          k=i|j;
          l=i&j;
          m=k^l;
          printf("%d, %d, %d, %d, %d\n", i, j, k, l, m);
          return 0;
      }
      

    • Options
    • A. 0, 0, 0, 0, 0
    • B. 0, 32, 32, 32, 32
    • C. 32, 32, 32, 32, 0
    • D. 32, 32, 32, 32, 32
    • Discuss
    • 6. Assuming a integer 2-bytes, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%x\n", -1<<3);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. fff8
    • C. 0 
    • D. -1
    • Discuss
    • 7. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          unsigned char i = 0x80;
          printf("%d\n", i<<1);
          return 0;
      }
      

    • Options
    • A. 0
    • B. 256
    • C. 100
    • D. 80
    • Discuss
    • 8. Bitwise & and | are unary operators

    • Options
    • A. True
    • B. False
    • Discuss
    • 9. Left shifting a number by 1 is always equivalent to multiplying it by 2.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. Bitwise & can be used to divide a number by powers of 2

    • Options
    • A. True
    • B. False
    • Discuss


    Comments

    There are no comments.

Enter a new Comment