google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 C Programming MCQ Questions and Answers - Conditional Statements Quiz - 7

C Programming MCQ Questions and Answers - Conditional Statements Quiz - 7

0




1) Choose a C Conditional Operator from the list.

A) ?:

B) :?

C) :<

D) <:


 

A

2) What is the other name for C Language ?: Question Mark Colon Operator.?

A) Comparison Operator
B) If-Else Operator
C) Binary Operator
D) Ternary Operator




D


3) Choose a syntax for C Ternary Operator from the list.

A) condition ? expression1 : expression2
B) condition : expression1 ? expression2
C) condition ? expression1 < expression2
D) condition < expression1 ? expression2

 



A

4) What is the output of the C statement.?

int main()
{
    int a=0;
    a = 5<2 ? 4 : 3;
    printf("%d",a);

    return 0;
}

A) 4
B) 3
C) 5
D) 2




B

5) What is the output of C Program.?

int main()
{
    int a=0;
    a = printf("4");
    printf("%d",a);

    return 0;
}

A) 04
B) compiler error
C) 40
D) 41




                                                                                    Explanation:                                                                                     a = printf("4");First printf prints 4. printf() returns 1.             Now the variable a=1; So 1 is printed next.

6) What is the output of the C Program.?

int main()
{
    int a=0;
    a = 5>2 ? printf("4"): 3;
    printf("%d",a);

    return 0;
}

A) compiler error
B) 14
C) 41
D) 0




                                                                                               Explanation: 5>2 is true. So expression1 i.e printf("4) is executed printing 4. Function printf() returns 1. So a value is 1.

7) What is the output of the C Program.?

int main()
{
    int a=0;
    a = (5>2) ? : 8;
    printf("%d",a);

    return 0;
}

A) 0
B) 1
C) 8
D) compiler error




B -                                                                    Explanation: expression1 = empty , expression2 = 8 , If no expression is specified, it will be treated as 1. 

8) What is the output of C Program.?

int main()
{
    int a=0, b;
    a = (5>2) ? b=6: b=8;
    printf("%d %d",a, b);

    return 0;
}

A) 6 6
B) 0 6
C) 0 8
D) compiler error




                                                                                       Explanation: Compiler error. a = (5>2) ? b=6: b=8; should be written as a = (5>2) ? b=6: (b=8);

9) Choose a correct statement regarding C Comparison Operators.

A) (x == y) Is x really equal to y.
(x != y) Is x not equal to y.
B) (x < y) Is x less than y
(x > y) Is x greater than y
C) (x <= y) Is x less than or equal to y.
(x >= y) Is x greater than or equal to y
D) All the above




D


10) Choose a statement to use C If Else statement.

A) else if is compulsory to use with if statement.
B) else is compulsory to use with if statement.
C) else or else if is optional with if statement.
D) None of the above




C

11) Choose a correct C Statement using IF Conditional Statement.

A) 
if( condition )
{
    //statements;
}

 

B) 
if( condition )
{
    //statements;
}
else
{
    //statements;
}

 

C) 
if( condition1 )
{
    //statements;
}
else if( condition2)
{
    //statements;
}
else
{
    //statements;
}

 

D) All the above.



D

12) What is the output of the C Program.?

int main()
{
    if( 4 > 5 )
    {
        printf("Hurray..\n");
    }
     printf("Yes");

    return 0;
}

A) Yes
B) Hurray..
    Yes
C) Hurray..Yes
D) Compiler error




A                                                                                       Explanation: if condition fails. So control will not enter Hurray printf statement.

13) What is the output of the C Program.?

int main()
{
    if( 4 > 5 )
        printf("Hurray..\n");
        printf("Yes");

    return 0;
}

A) Yes
B) Hurray..
Yes
C) Hurray..Yes
D) No Output



A                                                                                       Explanation: To include more than one statement inside If block, use { } braces. Otherwise, only first statement after if block is included. IF condition fails with false. So second if which is outside of If is executed.

14) What is the output of the C Program.?

int main()
{
    if( 4 < 5 )
        printf("Hurray..\n");
        printf("Yes");
    else
        printf("England")

    return 0;
}

A) Hurray..Yes
B) Hurray..
Yes
C) Compiler error
D) None of the above




C                                                                                           Explanation: If block includes only Single Hurray printf statement without curly braces { }. So second Yes printf statement is not part of IF block. Else should immediately follow IF block. Otherwise, compiler throws errors. To compile well, use { } braces for two printf statements or remove second printf after IF.

15) What is the output of the C Program.?

int main()
{
    if( 10 < 9 )
        printf("Hurray..\n");
    else if(4 > 2)
        printf("England");

    return 0;
}

A) England
B) Hurray..
C) Compiler error for missing else
D) None of the above



A                                                                                           Explanation: You can omit ELSE comfortably. Compiler will not complain above ELSE after IF or ELSE IF.

16) What is the output of C Program.?

int main()
{
    if( 10 > 9 )
        printf("Singapore\n");
    else if(4%2 == 0)
        printf("England\n");
        printf("Poland");
    return 0;
}

A) Singapore
B) Singapore
Poland
C) Singapore
England
Poland
D) England
Poland




B                                                                                       Explanation: Observe that Poland printf is not under ELSE IF as there are two statements without curly braces { }. IF condition is TRUE. So, The compiler don't check the ELSE IF its true or not.

17) What is the output of the C Program.?

int main()
{
    if(-5)
    {
        printf("Germany\n");
    }
    if(5)
    {
        printf("Texas\n");
    }
    printf("ZING");

    return 0;
}

A) ZING
B) Texas
ZING
C) Germany
Texas
ZING
D) Compiler error as a number can not be put as condition inside IF.




C                                                                                       Explanation: You can use any number inside IF as a condition. Positive Number or Negative Number evaluates to true. Number 0 Zero evaluates to false.

18) What is the output of the C Program.?

int main()
{
    if(10.0)
    {
        printf("Texas\n");
    }
    printf("ZING");

    return 0;
}

A) ZING
B) Texas
ZING
C) Compiler error.
D) None of the above.




B                                                                                           Explanation: You can use either Integer or Real numbers. 0 or 0.0 evaluates to false condition.

19) What is the output of C Program.?

int main()
{
    if("abc")
    {
        printf("India\n");
    }
    if('c')
    {
        printf("Honey\n");
    }
    printf("ZING");

    return 0;
}

A) ZING
B) Honey
ZING
C) India
ZING
D) India
Honey
ZING



D                                                                                           Explanation: You can use either Integer or Real numbers. 0 or 0.0 evaluates to false condition.

20) What is the output of C Program.?

int main()
{
    if(TRUE)
    {
        printf("India\n");
    }
    if(true)
    {
        printf("Honey\n");
    }
    printf("ZING");

    return 0;
}

A) India
ZING
B) Honey
ZING
C) India
Honey
ZING



D                                                                                       Explanation: There are no keywords (true) or (TRUE). These available in Java, JavaScript and other languages.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top