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

Control Instructions Questions and Answers

91.

If scanf() is used to store a value in a char variable then along with the value a carriage return also gets stored with it.

Answer: B

Correct answer: False

Nothing extra is stored. scanf("%c", &ch) reads exactly one character into the variable; the newline you typed afterwards is simply left in the input buffer, where it will be picked up by the next read. That is why a second %c so often appears to read nothing - it consumes the leftover newline.

Please log in or register to report this question.

92.

What will be the output of the program?

#include <stdio.h>
int main()
{
    int x=1, y=1;
    for(; y; printf("%d %d\n", x, y))
    {
        y = x++ <= 5;
    }
    printf("\n");
    return 0;
}

 

Answer: A

Correct answer: 2 1 3 1 4 1 5 1 6 1 7 0

The third clause of the for is the printf, so the values are printed after each pass through the body. The body sets y to the result of x++ <= 5, which is 1 while the old x is at most 5. So the pairs printed are 2 1, 3 1, 4 1, 5 1, 6 1 - and on the pass where x is 6 the comparison fails, giving 7 0, after which the condition y is false and the loop ends.

Please log in or register to report this question.

93.

A do-while loop terminates when its controlling expression evaluates to

Answer: B

Correct answer: Zero

A loop continues while its condition is true, that is non-zero, and stops when it evaluates to zero. The do-while differs from the others only in when the test happens - after the body rather than before - so the body always runs at least once.

Please log in or register to report this question.

94.

#include <stdio.h>
int main()
{
    int i;
    if (printf("0"))
        i = 3;
    else
        i = 5;
    printf("%d", i);
    return 0;
} 

 

Answer: C

Correct answer: 03

printf returns the number of characters written. It prints 0 - that is one character - and returns 1, which is true, so i becomes 3. The output is therefore the 0 from the condition followed by the 3: 03.

Please log in or register to report this question.

95.

What will be the output of the program?

#include <stdio.h>
int main()
{
    int a = 300, b, c;
    if(a >= 400)
        b = 300;
    c = 200;
    printf("%d, %d, %d\n", a, b, c);
    return 0;
}

 

Answer: C

Correct answer: 300, Garbage, 200

The condition \(300 \ge 400\) is false, so b = 300 never runs - and b, an uninitialised automatic variable, holds whatever was on the stack. c = 200 is a separate statement outside the if, so it always executes.

Please log in or register to report this question.

96.

What will be the output of the program?

#include <stdio.h>
int main()
{
    int i=3;
    switch(i)
    {
        case 1:
            printf("Hello\n");
        case 2:
            printf("Hi\n");
        case 3:
            continue;
        default:
            printf("Bye\n");
    }
    return 0;
}

 

Answer: A

Correct answer: Error: Misplaced continue

continue asks for the next iteration of a loop, and a switch is not a loop - nor is there any loop around this one. The compiler therefore rejects it. break would have been legal, since break applies to a switch as well as to a loop.

Please log in or register to report this question.

97.

Point out the error, if any in the program.

#include <stdio.h>
int main()
{
    int i = 1;
    switch(i)
    {
        printf("This is c program.");
        case 1:
            printf("Case1");
            break;
        case 2:
            printf("Case2");
            break;
    }
return 0;
}

 

Answer: C

Correct answer: No Error and prints "Case1"

The printf before the first case is legal but unreachable: a switch transfers control straight to a matching label, so nothing before the first label ever runs. i is 1, so case 1 executes and the break ends the switch.

Please log in or register to report this question.

98.

What is the output of this C code?

void main()

    {

        int i = 0;

        if (i == 0)

        {

            printf("Hello");

            continue;

        }

    }

 

Answer: D

Correct answer: Compile time error

continue is meaningful only inside a loop: it asks for the next iteration, and here there is no loop to iterate. Written inside a bare if with no enclosing loop, it is a compile-time error.

Please log in or register to report this question.

99.

Point out the error, if any in the program.

#include <stdio.h>
int main()
{
    int a = 10;
    switch(a)
    {
    }
    printf("This is c program.");
    return 0;
}

 

Answer: C

Correct answer: No Error

A switch body is just a compound statement, and an empty one is perfectly legal. Neither a case nor a default is required - the switch simply evaluates its controlling expression, finds no matching label, and does nothing. The program compiles and prints its message.

Please log in or register to report this question.

100.

In C++, which system - provided function is called when no handler is provided to deal with an exception?

Answer: A

Correct answer: terminate ( )

If an exception is thrown and no matching handler is found, C++ calls std::terminate(), which by default calls abort(). unexpected() belonged to the old dynamic exception specifications and is now removed; abort() is what terminate ends up calling rather than the function called first.

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