LearnFrenzy
Sign in Take a free test

Bitwise Operators · Exercise 2 of 4

Bitwise Operators Predict the Output

  • 12 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each program and choose what it prints. Every program was compiled and run with GCC/Clang behaviour on a 64-bit system, so the answers are the real output.

Question 11 Hard

What does this program print with GCC or Clang on x86-64 / ARM64?

main.c
#include <stdio.h>

int main(void) {
    int x = -16;
    printf("%d %d\n", x >> 2, x / 4);
    return 0;
}
A -4 -4
B 4 -4
C 1073741820 -4
D -4 4
Question page & discussion
Question 12 Medium

What is the output of the following program, compiled as C23?

main.c
#include <stdio.h>

int main(void) {
    unsigned flags = 0b0000'1010;
    unsigned mask  = 0b0000'0110;
    printf("%u %u %u\n", flags & mask, flags | mask, flags ^ mask);
    return 0;
}
A 2 14 12
B 2 14 8
C 6 10 12
D Compilation error
Question page & discussion
Up next · Exercise 3Find the Error8 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links