GATE CS 2024 Set 1 — Question 18
MCQ+1 / -0.33EasyControl FlowC ProgrammingProgramming & Data Structures
Programming & Data Structures → C Programming → Control Flow
Last updated
Question
Consider the following C program:Which one of the following statements is CORRECT?
#include
int main(){
int a = 6;
int b = 0;
while(a < 10) {
a = a / 12 + 1;
a += b;}
printf("%d", a);
return 0;}
A.
The program prints 9 as output
B.
The program prints 10 as output
C.
The program gets stuck in an infinite loop
D.
The program prints 6 as output
Correct answer
(C) The program gets stuck in an infinite loop
Solution
Let's trace the execution of the program step-by-step:
1.Initialization: The variables are initialized as and .
2.Loop Condition: The
while loop continues as long as .3.First Iteration:
- The condition is true.
-
a = a / 12 + 1: In C, integer division results in . Thus, . -
a += b: .
- The condition is true.
-
a = a / 12 + 1: Integer division results in . Thus, . -
a += b: .
More questions on C Programming
2024 Set 2 Q13Consider the following C program. Assume parameters to a function are evaluated from right to left.…2024 Set 2 Q17Let be the adjacency matrix of a simple undirected graph . Suppose is its own inverse.…2024 Set 1 Q17Given an integer array of size , we want to check if the array is sorted (in either ascending or…2024 Set 1 Q19Consider the following C program: [code] Assume that the input to the program from the command line…2024 Set 1 Q21In a tree, the requirement of at least half-full (50%) node occupancy is relaxed for which…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free