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

Control Instructions Questions and Answers

71.

The continue statement cannot be used with

Answer: D

Correct answer: switch

continue means “begin the next iteration”, so it belongs to the three loops. A switch has no iterations, so a continue written inside one is either applied to an enclosing loop or, if there is none, rejected. break, by contrast, works in all four.

Please log in or register to report this question.

72.

The output of the code below is

#include <stdio.h>
    int x;
    void main()
    {
        if (x)
            printf("hi");
        else
            printf("how are u");
    }

 

Answer: B

Correct answer: how are u

x is declared at file scope, so it has static storage duration and is zero-initialised - not left holding junk, as an uninitialised local would be. The condition is therefore false and the else branch runs.

Please log in or register to report this question.

73.

What will be the output of the program?

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

 

Answer: D

Correct answer: b = 100 c = 200

! binds far tighter than >=, so the condition is (!a) >= 400, not !(a >= 400). With a non-zero, !a is 0, and \(0 \ge 400\) is false - so b keeps its initial 100. The assignment c = 200 is a separate statement, outside the if altogether, so it always runs.

Please log in or register to report this question.

74.

By default, the data type of a constant without a decimal point is int, whereas the one with a decimal point is a double.

Answer: A

Correct answer: Yes

An unsuffixed integer literal such as 10 has type int, and one with a decimal point such as 3.14 has type double - not float, which catches many people out. Suffixes override this: 10L, 10U, 3.14f.

Please log in or register to report this question.

75.

When 1 is entered, The output of the code below is?

#include <stdio.h>
    void main()
    {
        int ch;
        printf("enter a value btw 1 to 2:");
        scanf("%d", &ch);
        switch (ch)
        {
        case 1:
            printf("1\n");
        default:
            printf("2\n");
        }
    }

 

Answer: C

Correct answer: 1 2

With no break after case 1, execution falls through into the default label - a label marks an entry point, not the boundary of a block. So both printf calls run, giving 1 and then 2 on the next line.

Please log in or register to report this question.

76.

Predict the output of the below program:

#include <stdio.h>
#define EVEN 0
#define ODD 1
int main()
{
    int i = 3;
    switch (i & 1)
    {
        case EVEN: printf("Even");
                break;
        case ODD: printf("Odd");
                break;
        default: printf("Default");
    }
    return 0;
}

 

Answer: B

Correct answer: Odd

i & 1 isolates the lowest bit, which is 1 for an odd number and 0 for an even one. With i equal to 3 the expression is 1, matching ODD, so Odd is printed. This bitwise test is a common alternative to i % 2.

Please log in or register to report this question.

77.

What will be the output of the program, if a short int is 2 bytes wide?

#include <stdio.h>
int main()
{
    short int i = 0;
    for(i<=5 && i>=-1; ++i; i>0)
        printf("%u,", i);
    return 0;
}

 

Answer: A

Correct answer: 1 ... 65535

The three clauses are not doing what they look like. The initialisation i<=5 && i>=-1 merely computes a value and throws it away; the condition is ++i, so the loop runs while the incremented value is non-zero; and the update i>0 changes nothing. So i simply counts up and is printed with %u, which reinterprets the negative half of the range as large positive numbers - ending when the value wraps back to 0. (Signed overflow is formally undefined, so this is a description of what happens in practice, not a guarantee.)

Please log in or register to report this question.

78.

Point out the error, if any in the while loop.

#include <stdio.h>
int main()
{
    void fun();
    int i = 1;
    while(i <= 5)
    {
        printf("%d\n", i);
        if(i>2)
            goto here;
    }
return 0;
}
void fun()
{
    here:
    printf("It works");
}

 

Answer: C

Correct answer: Error: goto cannot takeover control to other function

A goto can only jump to a label within the same function. The label here: is inside fun(), so it is not visible in main and the compiler reports an undefined label. Transferring control between functions is what a call, or setjmp/longjmp, is for.

Please log in or register to report this question.

79.

The output of the code below is

#include <stdio.h>
    void main()
    {
        int x = 0;
        if (x == 0)
            printf("hi");
        else
            printf("how are u");
            printf("hello");
    }

 

Answer: D

Correct answer: hihello

The condition is true, so the if branch prints hi. The second printf is outside the if-else altogether - there are no braces, so the else takes only the single statement that follows it - and therefore runs whichever branch was taken. The output is hihello, with no separator since neither string has a newline.

Please log in or register to report this question.

80.

The modulus operator cannot be used with a long double.

Answer: A

Correct answer: True

The % operator requires integer operands, so it cannot be applied to float, double or long double. For a floating-point remainder the library provides fmodl() in <math.h>.

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