basicc++mcq

C Programming MCQ Questions and Answers on Conditional Statements 2

softwaretechit.com

Learn C Programming MCQ Questions and Answers on Conditional Statements like Ternary Operator, IF, ELSE and ELSE IF statements. Easily attend exams after reading these Multiple Choice Questions.

Go through C Theory Notes on Conditional Operators before studying questions. 


1) What is the output of C Program.?

int main()

{

    int x=1;

    float y = 1.0;

    if(x == y)

    {

        printf(“Polon”);

    }

    if( 1 == 1.0)

    {

        printf(“Golfn”);

    }

 

    if( 1.0 == 1.0f )

    {

         printf(“Boxingn”);

    }

    return 0;

}

A) No Output

B) Boxing

C) Golf Boxing

D) Polo Golf Boxing

Answer [=]

D

Explanation:

Integer is promoted to float or double automatically before comparison. So all are equal.

1 == 1.0 == 1.0f

2) What is the output of C Program.?

int main()

{

    int a=9;

    if(a=8)

    {

        printf(“Kangaroon”);

    }

    printf(“Eggsn”);

 

    return 0;

}

A) No output

B) Eggs

C) Kangaroo Eggs

D) Compiler error

Answer [=]

C

Explanation:

a=8 is an assignment not comparison. IF( Non Zero) is always TRUE.

3) What is the output of C Program.?

int main()

{

    int a=9;

    if(a==5);

    {

        printf(“Kangaroon”);

    }

    printf(“Eggsn”);

 

    return 0;

}

A) Eggs

B) Kangaroo Eggs

C) No output

D) Compiler error

Answer [=]

B

Explanation:

Notice a Semicolon at the end of IF(a==5);. So IF block ends without any statements. Also, { } is not part of IF now. So it is executed without checking for any condition.

4) What is the output of C Program.?

int main()

{

    int a=9;

    if(a==9);

    {

        printf(“Ostrichn”);

    }

    elseif(a==8)

    {

        printf(“Eggsn”);

    }

   

    printf(“White”);

 

    return 0;

}

A) White

B) Ostrich White

C) No Ouput

D) Compiler error

Answer [=]

D

Explanation:

Notice IFELSE statement. There should be one SPACE between IF and ELSE.

5) What is the output of C Program.?

int main()

{

    int a=9;

    if(a==9)

    {

        printf(“Ostrichn”);

    }

    else;

    {

        printf(“Eggsn”);

    }

   

    printf(“White”);

 

    return 0;

}

A) White

B) Ostrich White

C) Ostrich Eggs White

D) Compiler Error

Answer [=]

C

Explanation:

Notice a Semicolon (;) at the end of ELSE. So ELSE is terminated immediately. Eggs Printf block is not part of ELSE and is always called.

6) What is the output of C Program.?

int main()

{

    int a=9, b=5, c=8;

    a=b=c=10;

    if(a==9)

    {

        printf(“Ostrichn”);

    }

    else

    {

        printf(“Eggsn”);

    }

   

    printf(“White”);

 

    return 0;

}

A) Ostrich Eggs White

B) Ostrich White

C) Eggs White

D) Compiler error as you can not assign to more than two variables at once.

Answer [=]

C

7) What is the output of C Program.?

int main()

{

    int a=9, b=5, c=8;

 

    if(!(a==9))

    {

        printf(“Bearn”);

    }

    else

    {

        printf(“Elephantn”);

    }

   

    printf(“Fox”);

 

    return 0;

}

A) Bear Fox

B) Elephant Fox

C) Fox

D) Compiler error

Answer [=]

B

Explanation:

Logical Not Operator ( ! ) changes true to false and false to true. So IF(false) is not executed.



8) What is the Priority of C Logical Operators.? NOT (!), AND (&&) and OR (||)

A) NOT (!) > AND (&&)  > OR (||)

B) NOT (!) > AND (&&) = OR (||)

C) AND (&&) > OR (||) > NOT (!)

D) AND (&&) = OR (||) > NOT (!)

Answer [=]

A

Explanation:

Logical NOT Operator in C has the highest priority.

9) What is the output of C Program.?

int main()

{

    int a=9, b;

   

    b = (a==9) ? (printf(“CATn”);printf(“DOGn”)) : (printf(“FOX”));

 

    return 0;

}

A) CAT DOG

B) FOX

C) CAT DOG FOX

D) Compiler error

Answer [=]

D

Explanation:

You can not put more than 1 statement inside expression1 or expression2 inside Ternary Operator.

(Condition)?(expression1):(expression2)

10) What is the output of C Program.?

int main()

{

    int a=9, b=6;

    if(a==9 && b==6)

    {

        printf(“Hockey”);

    }

    else

    {

        printf(“Cricket”);

    }

   

 

    return 0;

}

A) Cricket Football

B) Hockey Football

C) Football

D) Compiler error

Answer [=]

B

Explanation:

== operator has more priority than &&. Logical && AND operator returns true only if both expressions are true.

11) What is the output of C Program.?

int main()

{

    int a=9, b=6;

    if(a!=9 || b==6)

    {

        printf(“Hockeyn”);

    }

    else

    {

        printf(“Cricketn”);

    }

   

    printf(“Football”);

 

    return 0;

}

A) Cricket Football

B) Hockey Football

C) Football

D) Compiler error

Answer [=]

B

Explanation:

Logical OR || operator returns true if any one expression is true.

12) Choose a correct C Operator Priority.? Items in one group ( ) has same priority.

A) ( ! ) < (*, /, %) < (+, -) < ( <, <=, >, >=) < (==, !=) < (&&) < (||) < (=)

B) (( ! ) , (*, /, %) , (+, -)) < ( <, <=, >, >=) < (==, !=) < (&&) < (||) < (=)

C) ( ! ) > (*, /, %) > (+, -) > ( <, <=, >, >=) > (==, !=) > (&&) > (||) > (=)

D) (( ! ) , (*, /, %) , (+, -)) > ( <, <=, >, >=) > (==, !=) > (&&) > (||) > (=)

Answer [=]

C

Explanation:

( ! Logical NOT ) > (*, /, % Arithmetic) > (+, – Arithmetic) > ( <, <=, >, >= Relational) > (==, != Relational) > (&& Logical AND) > (|| Logical OR) > (= Assignment).

13) What is the output of C Program.?

int main()

{

    int a=5, b=8;

   

    if( a==5 && (b=9) )

    {

        printf(“Gorilla Glass=”);

    }

    printf(“%d %d”, a, b);

 

    return 0;

}

A) 5 8

B) 5 9

C) Gorilla Glass=5 8

D) Gorilla Glass=5 9

Answer [=]

D

Explanation:

In IF( a==5 && (b=9) ), && Operator checks both expressions for true or Non Zero value. So after checking a==5, b=9 is checked. Here b==9 is checking, but b=9 is assignment. Any NON-Zero value is true only. So b=9 now.

14) What is the output of C Program.?

int main()

{

    int a=5, b=8;

   

    if( a==5 || (b=9) )

    {

        printf(“Gorilla Glass=”);

    }

    printf(“%d %d”, a, b);

 

    return 0;

}

A) 5 8

B) 5 9

C) Gorilla Glass=5 8

D) Gorilla Glass=5 9

Answer [=]

C

Explanation:

Logical OR || checks wants only one TRUE condition. First expression (a==5) or even (a=5) is true. So second expression (b=9) is not evaluated and assignment not done. So b=8 only.



15) Choose a correct C Statement.

A) Nesting of ? : operator is possible.

B)

int main()

{

    int a=5, b=8;

   

    if( a>=5 || (b=9) )

    {

        printf(“Gorilla Glass”);

    }

 

    return 0;

}

//OUTPUT: Gorilla Glass

C)

int main()

{

    int a=5, b=8;

   

    if( a >= 5 && b <= 9 )

    {

        printf(“Gorilla Glass”);

    }

 

    return 0;

}

//OUTPUT: Gorilla Glass

D) All the above

Answer [=]

D

 

Leave a Reply

10 Best Artificial Intelligence Software|artificial intelligence tools 5 nft games to earn money | Best NFT games for earn crypto Earn Money From Minting NFTs| How to mint NFT for free Top 10 Things You Need To Know About Python List | python lists functions 10 Popular PHP frameworks for web developers| best php frameworks 12 Tips On How To Become a Python Developer | python For beginner 12 Best Nodejs Frameworks for App Development in 2022 how to create google web stories, Steps to create web stories Top 10 Features in Angular 13 Every Developer Should Know | Angular 13 Features 10 Best Angular UI Libraries | angular ui components | angular Project 10 Best Web Development Frameworks in 2022 Frontend & Backend 18 Best Open-Source and Free Database Software | best database software for beginners Top 10+ Best Java IDEs & Online Java Compilers | best java ide for beginners top 10 besic to andvance java books |java books for beginer Top 5 Themes For Blogger, professional blogger theme download BEST Python Courses Online,Top 10 Courses to Learn Python in 2022 Top 13 python libraries for data science