C If .. Else MCQ Questions and Answers
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int num = 5; if (num > 10) { printf("Number is greater than 10."); } else { printf("Number is less than or equal to 10."); } return 0; }A. Number is greater than 10.
B. Number is less than or equal to 10.
C. Compilation error
D. Runtime error
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int x = 10; if (x > 5) printf("x is greater than 5"); else printf("x is less than or equal to 5"); return 0; }A. x is greater than 5
B. x is less than or equal to 5
C. Compilation error
D. Runtime error
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int a = 3, b = 7; if (a > b) { printf("a is greater"); } else if (a < b) { printf("b is greater"); } else { printf("a and b are equal"); } return 0; }A. a is greater
B. b is greater
C. a and b are equal
D. No output
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int score = 85; char grade; if (score >= 90) grade = 'A'; else if (score >= 80) grade = 'B'; else if (score >= 70) grade = 'C'; else grade = 'D'; printf("Grade: %c", grade); return 0; }A. Grade: A
B. Grade: B
C. Grade: C
D. Grade: D
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int num = 10; if (num % 2 == 0) { printf("%d is even.", num); } else { printf("%d is odd.", num); } return 0; }A. 10 is even.
B. 10 is odd.
C. Compilation error
D. Runtime error
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int age = 18; if (age <= 18) { printf("You are a teenager."); } else { printf("You are an adult."); } return 0; }A. You are a teenager.
B. You are an adult.
C. Compilation error
D. Runtime error
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int num = 15; if (num % 2 == 0) { printf("%d is even.", num); } else if (num % 2 != 0) { printf("%d is odd.", num); } return 0; }A. 15 is even.
B. 15 is odd.
C. Compilation error
D. Runtime error
Q. What is the output of the following C code snippet?
#include <stdio.h> int main() { int num = 5; if (num < 10) { printf("Number is less than 10."); } else if (num > 10) { printf("Number is greater than 10."); } else { printf("Number is equal to 10."); } return 0; }A. Number is less than 10.
B. Number is greater than 10.
C. Number is equal to 10.
D. Compilation error