Loading...

C Multiple Choice Questions

Our C questions and answers focuses on all areas of C programming language covering 100+ topics in C

C Decision making & Loops-3 MCQs

C Decision making & Loops-3


1. How long the following loop runs?
for(x = 1; x = 3; x++)

a) Three times
b) Four times
c) Forever
d) Never



2. A switch statement is used to

a) To use switching variable
b) Switch between function in a programchar
c) Switch from one variable to another variable
d) To choose from multiple possibilities which may arise due to different values of a single variable



3. If the following loop is implemented
void main() {
int num = 0;
do {
- - num;
printf(“%d”, num);
num ++;
}
while(num >= 0);
}

a) A run time error will be reported
b) The program will not enter into the loop
c) The loop will run infinitely many times
d) There will be a compilation error reported



4. What is the value of ‘grade’ after the switch statement is executed?
marks = 80;
switch(marks) {
  case 60:
    grade = ‘C’;
    break;
  case 70:
    grade = ‘B’;
    break;
  case 80:
    grade = ‘A’;
    break;
  default:
    grade = ‘E’;

a) A
b) B
c) C
d) E



5. If switch feature is used, then

a) Default case must be present
b) Default case, if used, should be the last case
c) Default case, if used, can be placed anywhere
d) None of the above



6. In the context of "break" and "continue" statements in C, pick the best statement.

a) "break" and "continue" can be used in "for", "while", "do-while" loop body and "switch" body
b) "break" and "continue" can be used in "for", "while" and "do-while" loop body. But only "break" can be used in "switch" body
c) "break" and "continue" can be used in "for", "while" and "do-while" loop body. Besides, "continue" and "break" can be used in "switch" and "if-else" body
d) "break" can be used in "for", "while" and "do-while" loop body



7. In _______, the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other.

a) Loop unrolling
b) Strength reduction
c) Loop concatenation
d) Loop jamming



8. What will be the output of the following piece of code?
#include <stdio.h>

int main() {
  int value = 0;
  if(value)
    printf("well done");
  printf("Algbly");
  return 0;
}

a) well done AlgblY
b) Algbly
c) complier error
d) None of these



9. What will be the output of the following piece of code?
#include <stdio.h>

int main() {
  for(i = 0;i < 10; i++);
  printf("%d", i);
  return 0;
}

a) 10
b) 0123456789
c) Syntax error
d) 0
e) Infinite loop



10. What will be the value of the digit?
#include <stdio.h>

int main() {
  int digit = 0;
  for(; digit <= 9; )
digit++;
digit *= 2;
--digit;
  return 0;
}

a) -1
b) 17
c) 19
d) 16



- Related Topics