Write the output of the following C program #include <stdio.h> int main (void)…

2014

Write the output of the following C program

#include <stdio.h>

  int main (void)
  {
  int shifty;
  shifty = 0570;
  shifty = shifty >>4;
  shifty = shifty <<6;
  printf("the value of shifty is %o",shifty);
  }

  1. A.

    the value of shifty is 15c0

  2. B.

    the value of shifty is 4300

  3. C.

    the value of shifty is 5700

  4. D.

    the value of shifty is 2700

Attempted by 958 students.

Show answer & explanation

Correct answer: D

Step 1: shifty = 0570

Leading zero → Octal literal!

Convert 0570 octal to decimal:

5×64 + 7×8 + 0 = 320 + 56 + 0 = 376

Step 2: shifty = shifty >> 4

Right shift by 4 = divide by 2⁴ = divide by 16

376 / 16 = 23 (decimal)

Step 3: shifty = shifty << 6

Left shift by 6 = multiply by 2⁶ = multiply by 64

23 × 64 = 1472 (decimal)

Step 4: printf("%o", shifty)

%o = Octal format!

Convert 1472 decimal → octal:

1472 ÷ 8 = 184 r 0 184 ÷ 8 = 23 r 0 23 ÷ 8 = 2 r 7 2 ÷ 8 = 0 r 2

1472 decimal = 2700 octal

Answer: D) the value of shifty is 2700

Key concepts:

  • 0 se start → Octal literal

  • >>4 = ÷16, <<6 = ×64

  • %o = output in octal

Explore the full course: Isro