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

Control Instructions Questions and Answers

111.

What will be the output of the program?

#include <stdio.h>
int main()
{
    int x = 10, y = 20;
    if(!(!x) && x)
        printf("x = %d\n", x);
    else
        printf("y = %d\n", y);
    return 0;
}

 

Answer: C

Correct answer: x = 10

!x is 0 since x is non-zero, and !(!x) is therefore 1 - the double negation normalises any non-zero value to 1. The condition 1 && 10 is true, so the first branch runs and prints the value of x, which the logical operators never altered: 10.

Please log in or register to report this question.

112.

What will be the output of the program?

#include <stdio.h>
int main()
{
    char ch;
    if(ch = printf(""))
        printf("It matters\n");
    else
        printf("It doesn't matters\n");
    return 0;
}

 

Answer: B

Correct answer: It doesn't matters

printf("") writes nothing and therefore returns 0 - the count of characters written. That 0 is assigned to ch, and the value of the assignment is also 0, which is false. So the else branch runs.

Please log in or register to report this question.

Loading…
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