GateAI
Programming in C

GATE CSE 2024 Set 1 · Q18

MCQ1 markEasy

Time

Consider the following C program:#include <stdio.h> int main() { int a = 6; int b = 0; while(a < 10) { a = a / 12 + 1; a += b; } printf("%d", a); return 0; }Which one of the following statements is CORRECT?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) The program gets stuck in an infinite loop

Programming in C

Let us trace the execution of the program step by step:

  1. Initial values of variables:

    • a = 6

    • b = 0

  2. Iteration 1:

    • Check condition: a < 10   ⟹  6<10\implies 6 < 10, which evaluates to true.

    • a = a / 12 + 1: Since a is an integer, integer division 6/126 / 12 evaluates to 00. Thus, a=0+1=1a = 0 + 1 = 1.

    • a += b: a=1+0=1a = 1 + 0 = 1.

  3. Iteration 2:

    • Check condition: a < 10   ⟹  1<10\implies 1 < 10, which evaluates to true.

    • a = a / 12 + 1: 1/12=01 / 12 = 0, so a=0+1=1a = 0 + 1 = 1.

    • a += b: a=1+0=1a = 1 + 0 = 1.

  4. For all subsequent iterations, a remains 11, and the condition a < 10 will always be true. Therefore, the loop will never terminate, resulting in an infinite loop.

Thus, statement (C) is correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q18 of the GATE CSE 2024 Set 1 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 20 of them are 1-mark MCQs like this one, and GATE CSE 2024 Set 1 has 3.

How GATE tests Programming in C

More from GATE CSE 2024 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2024 Set 1 · Q18 · MCQ

Consider the following C program: #include int main() { int a = 6; int b = 0; while(a Which one of the following statements is CORRECT?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.