C language MCQ:
1. What is the correct way to declare an integer variable in C?
A. integer x;
B. int x;
C. variable x;
D. x as Integer;
Answer: B. int x;
.png)
2. Which of the following is not a valid C identifier (variable name)?
A. _variableName
B. 123variable
C. myVar
D. Var123
Answer: B. 123variable
3. What is the purpose of the sizeof operator in C?
A. To calculate the size of a variable in bytes
B. To calculate the sum of two numbers
C. To find the remainder of a division operation
D. To calculate the square root of a number
Answer: A. To calculate the size of a variable in bytes
4. Which operator is used for comparing two values in C?
A. =
B. ==
C. !=
D. <-
Answer: B. ==
5. What is the output of the following code snippet?c
int x = 5; printf("%d", x++);
A. 5
B. 6
C. 7
D. Compiler Error
Answer: A. 5
6. In C, what is the purpose of the break statement within a switch statement?
A. To exit the entire program
B. To jump to the next case label
C. To exit the switch statement and continue with the code after it
D. To repeat the current case statement
Answer: C. To exit the switch statement and continue with the code after it
7. What is the correct syntax for a for loop in C?
A. for (int i = 0; i < 10; i++)
B. for (int i = 0; i++)
C. for (i = 0; i < 10)
D. loop (i = 0; i < 10)
Answer: A. for (int i = 0; i < 10; i++)
8. What is the purpose of the & operator in C?
A. To perform logical AND operation
B. To access the memory address of a variable
C. To concatenate two strings
D. To subtract two numbers
Answer: B. To access the memory address of a variable
9. What is the output of the following code snippet?c
int a = 10, b = 20; printf("%d", a > b ? a : b);
A. 10
B. 20
C. Compiler Error
D. 30
Answer: B. 20
10. In C, what is the purpose of the malloc function?
A. To calculate mathematical expressions
B. To allocate memory dynamically
C. To perform file I/O operations
D. To find the maximum value in an array
Answer: B. To allocate memory dynamically
0 Comments