basicc++mcq

C MCQ Questions and Answers on Loops While For Do While 1

softwaretechit.com

Learn C Programming MCQ Questions and Answers on Loops like While Loop, For Loop and Do While Loop. Loops execute a series of statements until a condition is met or satisfied. Easily attend exams after reading these Multiple Choice Questions.

Go through C Theory Notes on Loops before studying questions. 

 


1) Choose a right C Statement.

A) Loops or Repetition block executes a group of statements repeatedly.

B) Loop is usually executed as long as a condition is met.

C) Loops usually take advantage of Loop Counter

D) All the above.

Answer [=]

D

2) Loops in C Language are implemented using.?

A) While Block

B) For Block

C) Do While Block

D) All the above

Answer [=]

D

3) Which loop is faster in C Language, for, while or Do While.?

A) for

B) while

C) do while

D) All work at same speed

Answer [=]

D

4) Choose correct C while loop syntax.

A)

while(condition)

{

    //statements

}

B)

{

    //statements

}while(condition)

C)

while(condition);

{

    //statements

}

D)

while()

{

    if(condition)

    {

        //statements

    }

}

Answer [=]

A

5) Choose a correct C for loop syntax.

A)

for(initalization; condition; incrementoperation)

{

    //statements

}

B)

for(declaration; condition; incrementoperation)

{

    //statements

}

C)

for(declaration; incrementoperation; condition)

{

    //statements

}

D)

for(initalization; condition; incrementoperation;)

{

    //statements

}

Answer [=]

A

Explanation:

increment or decrement operation at third place.

6) Choose a correct C do while syntax.

A)

dowhile(condition)

{

    //statements

}

B)

do while(condition)

{

    //statements

}

C)

do

{

    //statements

 

}while(condition)

D)

do

{

    //statements

 

}while(condition);

Answer [=]

D

Explanation:

Semicolon after while(condition) is a must.

7) What is the output of C Program.?

int main()

{

    while(true)   

    {

        printf(“RABBIT”);

        break;

    }

   

    return 0;

}

A) RABBIT

B) RABBIT is printed unlimited number of times.

C) No output

D) Compiler error.

Answer [=]

D

Explanation:

while(TRUE) or while(true) does not work. true is not a keyword.



8) What is the output of C Program.?

int main()

{

    int a=5;

   

    while(a==5)   

    {

        printf(“RABBIT”);

        break;

    }

 

    return 0;

}

A) RABBIT is printed unlimited number of times

B) RABBIT

C) Compiler error

D) None of the above.

Answer [=]

B

Explanation:

If there is no BREAK statement, while loop runs continuously util the computer hangs. BREAK causes the loop to break once and the statement below the while if any will be executed.

9) What is the output of C Program.?

int main()

{

    int a=5;

   

    while(a=123)   

    {

        printf(“RABBITn”);

        break;

    }

    printf(“GREEN”);

   

    return 0;

}

A) GREEN

B) RABBIT GREEN

C) RABBIT is printed unlimited number of times.

D) Compiler error.

Answer [=]

B

Explanation:

while(a=123)  = while(123) = while(Non Zero Number). So while is executed. BREAK breaks the loop immediately. Without break statement, while loop runs infinite number of times.

10) What is the output of C Program.?

int main()

{

    int a=5;

   

    while(a >= 3);

    {

        printf(“RABBITn”);

        break;

    }

    printf(“GREEN”);

   

    return 0;

}

A) GREEN

B) RABBIT GREEN

C) RABBIT is printed infinite times

D) None of the above

Answer [=]

D

Explanation:

Notice a semicon(;) after while condition. It makes the printf and break statement blocks isolate.

while(a >= 3)

{

    ;//infinite loop

}

{

    printf(“RABBITn”);

    break;

}

11) What is the output of C Program.?

int main()

{

    int a=25;

   

    while(a <= 27)

    {

        printf(“%d “, a);

        a++;

    }

 

    return 0;

}

A) 25 25 25

B) 25 26 27

C) 27 27 27

D) Compiler error

Answer [=]

B

Explanation:

a++ is equivalent to a=a+1;

a is incremented each time.

12) What is the output of C Program.?

int main()

{

    int a=32;

   

    do

    {

        printf(“%d “, a);

        a++;

    }while(a <= 30);

 

    return 0;

}

A) 32

B) 33

C) 30

D) No Output

Answer [=]

A

Explanation:

do { } block is executed even before checking while(condition) at least once. This prints 32. To loop for the second time, while (32 <= 30) fails. So, loop is quit.

13) What is the output of C Program.?

int main()

{

    int a=32;

   

    do

    {

        printf(“%d “, a);

        a++;

        if(a > 35)

            break;

    }while(1);

 

    return 0;

}

A) No Output

B) 32 33 34

C) 32 33 34 35

D) Compiler error

Answer [=]

C

Explanation:

while(1) is infinite loop. So we kept if(condition) to break the loop. a++ is equivalent to a=a+1;

14) Choose a correct C Statement.

A) a++ is (a=a+1) POST INCREMENT Operator

B) a– is (a=a-1) POST DECREMENT Opeartor –a is (a=a-1) PRE DECREMENT Opeator

C) ++a is (a=a+1) PRE INCRMENT Operator

D) All the above.

Answer [=]

D



15) Choose correct Syntax for C Arithmetic Compound Assignment Operators.

A) a+=b is (a= a+ b) a-=b is (a= a-b)

B) a*=b is (a=a*b) a/=b is (a = a/b)

C) a%=b is (a=a%b)

D) All the above.

Answer [=]

D

16) What is the output of C Program.?

int main()

{

    int k, j;

   

    for(k=1, j=10; k <= 5; k++)

    {

        printf(“%d “, (k+j));

    }

 

    return 0;

}

A) compiler error

B) 10 10 10 10 10

C) 11 12 13 14 15

D) None of the above

Answer [=]

C

Explanation:

You can initialize any number of variables inside for loop.

17) What is the output of C Program.?

int main()

{

    int k;

   

    for(k=1; k <= 5; k++);

    {

        printf(“%d “, k);

    }

 

    return 0;

}

A) 1 2 3 4 5

B) 1 2 3 4

C) 6

D) 5

Answer [=]

C

Explanation:

Semicolon at the end of for(); isolates the below print() block. After for loop is over, k value is 6.

for(k=1; k <= 5; k++)

{

    ;

}

{

    printf(“%d “, k);

}

18) What is the output of C Program.?

int main()

{

    int k;

   

    for(;;)

    {

        printf(“TESTINGn”);

        break;

    }

 

    return 0;

}

A) No Output

B) TESTING

C) Compiler error

D) None of the above

Answer [=]

B

Explanation:

for(;;) loop need not contain any initialization, condition and incre/decrement sections. All are optional. BREAK breaks the FOR Loop.

19) What is the output of C Program.?

int main()

{

    int k;

   

    for(printf(“FLOWER “); printf(“YELLOW “); printf(“FRUITS “))

    {

        break;

    }

 

    return 0;

}

A) Compiler error

B) FLOWER FRUITS

C) FLOWER YELLOW

D) FLOWER YELLOW FRUITS

Answer [=]

C

Explanation:

for(anything; anything; anything) is Ok. printf(“YELLOW”) prints YELLOW and returns 1 as result. So for loop runs forever. Actually break is saving us from quitting the for loop. Only after checking condition and executing the loop statements, third section is executed. break causes the loop to quit without incre/decrement section.

20) What is the way to suddenly come out of or Quit any Loop in C Language.?

A) continue; statement

B) break; statement

C) leave; statement

D) quit; statement

Answer [=]

B

Explanation:

eg.

while(condition)

{

break;

}

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