Machine-translated by Google. Questions are authored in English.
Top

Discussion

Comment on the output of this C code?
   

int main()
    {
        int i, n, a = 4;
        scanf("%d", &n);
        for (i = 0; i < n; i++)
            a = a * 2;
    }

 

  • A.Logical Shift left
  • B.No output
  • C.Arithmetic Shift right
  • D.bitwise exclusive OR

Answer: B

Correct answer: No output

The loop multiplies a by 2 on each of the n passes, so a ends as \(4 \times 2^n\). But the program never prints anything - there is no printf after the loop - so the computed value is simply discarded when main returns. No output.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.