Which of the following is not an infinite loop ? (A) int i = 1; while (1) { i++ ; } (B) for ( ; ; ) ; while (t) { f = 1; } (D) int y, x = 0 ; do { y = x; } while (x == 0);
(C) int t = 0, f ;
int t = 0, f ; while (t) { f = 1; }
Option 3 is the odd one out — and its body does not execute even once.
Take each in turn.
Option 1. while (1) tests the constant 1, which in C is always true, and nothing inside the body ever changes that. i increments for ever (overflowing along the way, which is undefined behaviour but does not end the loop). Infinite.
Option 2. for ( ; ; ) omits all three expressions. An omitted condition in a for header is defined by the language to be true, so this is the idiomatic C infinite loop, more compact than while (1). Infinite.
Option 3. t is initialised to 0. A while loop tests before it enters, and 0 is false in C, so control passes straight over the body — f = 1; never runs. The loop terminates immediately. Not infinite — the answer.
Option 4. A do-while runs its body first and tests afterwards. x is 0 and only y is assigned inside, so x == 0 is true on every test and the loop never ends. Infinite.
| Option | Test | Body runs | Verdict |
|---|---|---|---|
| 1 | while (1) | For ever | Infinite |
| 2 | Omitted → true | For ever | Infinite |
| 3 | while (0) | Never | Terminates |
| 4 | x == 0, always true | For ever | Infinite |
The two ideas being tested are worth separating. First, C has no boolean type in the classical sense: any non-zero value is true and only zero is false, so while (t) with t zero is simply while (false). Second, while is a pre-test loop and do-while a post-test loop — which is exactly why options 3 and 4, superficially similar, behave oppositely: swap their loop forms and the answers swap too.
A classic trap the question avoids but is worth noting : writing while (x = 0) with a single equals sign assigns rather than compares, yielding 0 and so terminating — a bug that compiles cleanly. Option 4 correctly uses ==.
Hence, the loop that is not infinite is option 3.
The function "isalnum( )" returns a non-zero value if the character is alphanumeric and zero otherwise. What is header file to be used in the main program ?
To read a integer variable, find the correct format given below :
Int m;
Find the correct list, which is the reverse (at all levels) of the given list :
[[4, 7, 8], 2, 9, [19, 6], 20, 3]
(i) 3, 20
(ii) 9, 2
(iii) [6, 19]
(iv) [8, 7, 4]
The three types of loops available in C language are
i. for
ii. while
iii. do-while
Which loops do not operate without testing the condition even once ?
Match the following :
| List – I | List – II |
| a. associativity | i. memory storage |
| b. # define | ii. if-then-else |
| c. auto | iii. operators with equal precedence |
| d. conditional operator | iv. define operator |
Codes :
Assertion (A) : 'C' uses many data types such as integers (short and long) and float etc.
Reason (R) : Conversion specifier used for short unsigned integer is % lu.
Which bitwise operator is suitable for turning off a particular bit in a number ?
Which storage class is used for the variables that are often required in a program ?
Which is not a proper way of array declaration ?
Exponentiation operation in C is carried out as
Which of the following is NOT a state function or state variable in a thermodynamic system?