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

Control Instructions Questions and Answers

11.

The correct sequence to write a loop statement is formed

I. body
II. main( )
III. test condition
IV. initialization

Exam Year(s)

UGC NET - 2012,

Answer: D

The correct sequence for writing a loop is main( ), initialization, test condition, body, which is II, IV, III, I, option (D). A C program starts in the function main( ), the loop variable is given its initial value, the test condition is then checked before each pass, and the body of the loop runs if the test is true. Option (A) starts with the body. Option (B) leaves out main( ) at the start. Option (C) places the test before the initialization and puts the body last without a start.

Please log in or register to report this question.

12.

List - IList - II
a. if statementi. case
b. do statementii. return
c. switch statementiii. while
d. main statementiv. else

Codes :
(a) (b) (c) (d)

Exam Year(s)

UGC NET - 2013,

Answer: D

The matching is (a)-(iv), (b)-(iii), (c)-(i), (d)-(ii), which is option (D). An if statement is paired with else, a do statement with while in the do-while loop, and a switch statement with case labels. The main function returns a value to the operating system through return. Options (A), (B) and (C) pair if with while or switch with else, which are not constructs that belong together.

Please log in or register to report this question.

13.

int Net = 0;

if x \lt 50
    if (y \gt 5)
        Net = x + y;
    else
        Net = x - y;

For this C program segment, x = 55 and y = 5, then the value Net is

Exam Year(s)

UGC NET - 2013,

Answer: A

The value of Net is 0, the first option. In the segment the else belongs to the inner if, since an else attaches to the nearest if. The outer test \(x \lt 50\) fails for x = 55, so the inner statement is never reached and Net keeps its initial value of 0.

The values 60 (x + y) and 50 (x - y) would be the result if the inner if were reached, and 55 is the value of x, which is not assigned to Net.

Please log in or register to report this question.

14.

How many times the word 'print' shall be printed by the following program segment ? for (i=1, i≤2,i++) for (j=1,j≤2,j++) for(k=1,k≤2,k++) printf("print/n")

Exam Year(s)

UGC NET - 2013,

Answer: D

The word 'print' is printed 8 times, option (D). The three loops are nested, and each runs for the two values 1 and 2 of its variable, since the condition is less than or equal to 2. The innermost statement therefore executes 2 x 2 x 2 = 8 times. The values 1 (a single execution) and 3 or 6 would come from counting the loop variables one at a time or adding the counts, but nested loops multiply, they do not add. If the condition were strictly less than 2 each loop would run once and the answer would be 1, which is why the printed sign matters here: it is a less than or equal to sign, not a bare less than sign.

Please log in or register to report this question.

15.

The keyword ‘break’ cannot be simply used within:

Answer: B

Correct answer: if-else

break belongs to loops and switch: it exits the nearest enclosing for, while, do-while or switch. An if is not one of those, so a break written directly inside an if either escapes the loop containing the if or, if there is no such loop, fails to compile.

Please log in or register to report this question.

16.

#include <stdio.h>
 
int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf("%d", i);
    return 0;
}

 

Answer: B

Correct answer: 1

i++ yields the old value and then increments, so the loop keeps going while the old value is non-zero. Starting at 65000 the variable climbs to the maximum for an unsigned int and then wraps round to 0 - wrapping is defined behaviour for unsigned types. On that pass the test sees 0 and stops, but i has already been incremented once more, to 1.

Please log in or register to report this question.

17.

The output of the code below is

#include <stdio.h>
    void main()
    {
        char *ch;
        printf("enter a value btw 1 to 3:");
        scanf("%s", ch);
        switch (ch)
        {
        case "1":
            printf("1");
            break;
        case "2":
            printf("2");
            break;
        }
    }

 

Answer: C

Correct answer: Compile time error

Two things are wrong, and either alone is fatal. The controlling expression ch is a pointer, not an integer type; and the case labels "1" and "2" are string literals, which are not integer constants. (The scanf into an uninitialised pointer would also be undefined behaviour, but the program never gets that far.)

Please log in or register to report this question.

18.

Which loop is guaranteed to execute at least once?

Answer: C

Correct answer: do while

A do-while tests its condition after the body, so the body always runs at least once. for and while test first, and so may not run at all. This makes do-while the natural choice for reading input and then validating it.

Please log in or register to report this question.

19.

Which of the following statements are correct about an if-else statements in a C-program?

1. Every if-else statement can be replaced by an equivalent statements using   ?: operators

2. Nested if-else statements are allowed.

3. Multiple statements in an if block are allowed.

4. Multiple statements in an else block are allowed.

Answer: D

Correct answer: 2, 3, 4

2, 3 and 4 are true: if-else statements nest freely, and either branch may hold as many statements as you like inside braces.

1 is false. The conditional operator ?: combines expressions, not statements, so it cannot replace an if-else whose branches contain declarations, loops, or several statements. It replaces only the special case where both branches produce a value.

Please log in or register to report this question.

20.

Which of the following is correct with respect to “Jump Statements” in C?

Answer: D

Correct answer: All of the above.

C has four jump statements, and three of them are listed: goto, which transfers to a label in the same function; continue, which starts the next iteration; and break, which leaves a loop or switch. The fourth is return.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Control Instructions Questions and Answers || Control Instructions MCQ Questions and Answers || Control Instructions GK Questions and Answers || Control Instructions GK MCQ Questions || Control Instructions Multiple Choice Questions and Answers || Control Instructions GK || GK on Control Instructions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming