22226 PCI MCQ (Programming in C) | Unit 3: Control Structures

cwipedia

Department of Computer Engineering

Academic Year 2020-21


Class: Computer & IT

Subject: 22226 PCI (Programming in C) MCQ 


Unit 3: Control Structures


MCQ Question Bank with Answers


2nd SEM ALL SUBJECT MCQ:           click here

     



To Download PDF scroll to the bottom


1. In the following loop construct, which one is executed only once always.Γ‚ Γ‚ Γ‚ Γ‚ for(exp1; exp2; exp3)

A. exp1

B. exp3

C. exp1 and exp3

D. exp1, exp2 and exp3

Ans : A


2. The continue statement cannot be used with

A. for

B. while

C. do while

D. switch

Ans : D


3. Which keyword can be used for coming out of recursion?

A. return

B. break

C. exit

D. both A and B

Ans : A


4. goto can be used to jump from main to within a function?

A. TRUE

B. FALSE

C. May Be

D. Can't Say

Ans : B

5. Which of the following is an invalid if-else statement?

A. if (if (a == 1)){}

B. if (a){}

C. if ((char) a){}

D. if (func1 (a)){}

Ans : A


6. Switch statement accepts.

A. int

B. char

C. long

D. All of the above

Ans : D


7. Which loop is guaranteed to execute at least one time.

A. for

B. while

C. do while

D. None of the above

Ans : C


8. A labeled statement consist of an identifier followed by

A. ;

B. :

C. ,

D. =

Ans : B


9. do-while loop terminates when conditional expression returns?

A. One

B. Zero

C. Non - zero

D. None of the above

Ans : B


10. c = (n) ? a : b; can be rewritten as exp1 ? exp2 : exp3;

A. if(n){c = a;}else{c = b;}

B. if(!n){c = a;}else{c = b;}

C. if(n){c = b;}else{c = a;}

D. None of the above

Ans : A


11. The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________

a) break

b) exit(0)

c) abort()

d) terminate

Answer: a

12. What will be the correct syntax for running two variable for loop simultaneously?

a)

  for (i = 0; i < n; i++)

   for (j = 0; j < n; j += 5)

b)

for (i = 0, j = 0; i < n, j < n; i++, j += 5)

c)

 for (i = 0; i < n;i++){}

   for (j = 0; j < n;j += 5){}

d) none of the mentioned

Answer: b

13. Which for loop has a range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?

a) for (i = n; i>0; i–)

b) for (i = n; i >= 0; i–)

c) for (i = n-1; i>0; i–)

d) for (i = n-1; i>-1; i–)

Answer: d

14. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?

a) variable

b) function

c) typedef

d) macros

Answer: d

15. What will be the output of the following C code?

  1.    #include <stdio.h>

  2.    int main()

  3.    {

  4.        short i;

  5.        for (i = 1; i >= 0; i++)

  6.            printf("%d\n", i);

  7.  

  8.    }

a) The control won’t fall into the for loop

b) Numbers will be displayed until the signed limit of short and throw a runtime error

c) Numbers will be displayed until the signed limit of short and program will successfully terminate

d) This program will get into an infinite loop and keep printing numbers with no errors

Answer: c

16. What will be the output of the following C code?

  1.    #include <stdio.h>

  2.    void main()

  3.    {

  4.        int k = 0;

  5.        for (k)

  6.            printf("Hello");

  7.    }

a) Compile time error

b) hello

c) Nothing

d) Varies

Answer: a

17. What will be the output of the following C code?

  1.    #include <stdio.h>

  2.    void main()

  3.    {

  4.        int k = 0;

  5.        for (k < 3; k++)

  6.        printf("Hello");

  7.    }

a) Compile time error

b) Hello is printed thrice

c) Nothing

d) Varies

Answer: a

18. What will be the output of the following C code?

  1.    #include <stdio.h>

  2.    void main()

  3.    {

  4.        double k = 0;

  5.        for (k = 0.0; k < 3.0; k++)

  6.            printf("Hello");

  7.    }

a) Run time error

b) Hello is printed thrice

c) Hello is printed twice

d) Hello is printed infinitely

Answer: b

Download



Happy Learning!

cwipedia.in


Comments