GATE CS 2024 Set 1 | Question 18

Programming & Data Structures › Basics & Control Structures · MCQ · 1 mark · Answer: C

  1. Question 18Programming & Data Structuresmcq1 mark
    Consider the C program:
    int main(){
       int a = 6;
       int b = 0;
       while(a < 10) {
          a = a / 12 + 1;
          a += b;
       }
       printf("%d", a);
       return 0;
    }
    Which statement is CORRECT?
    • A.
      The program prints 9
    • B.
      The program prints 10
    • C.
      The program gets stuck in an infinite loop
      ✓
    • D.
      The program prints 6

    Answer: C

    Solution

    Answer: (C) The program gets stuck in an infinite loop Start (<10), . Inside: (integer division), then . Now . Next iteration: , . stays forever, so the loop never ends.

More GATE PYQ on Basics & Control Structures

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2024 Set 1 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →