Multiple-choice question
Here are some multiple-choice questions (MCQs) related to the C programming language: Mcqs answer given in end

Mcqs
a. int
b. float
c. boolean
d. char
2. What is the output of the following code snippet?
```c
#include <stdio.h>
int main() {
printf("%d", sizeof('a'));
return 0;
}
```
a. 1
b. 2
c. 4
d. 8
3. What is the correct way to declare an array in C?
a. int array[10];
b. array[10] int;
c. array int[10];
d. array[10];
4. What is the result of the following expression?
```c
5 + 2 * 3 / 2 - 1
```
a. 7
b. 8
c. 9
d. 10
5. What is the output of the following code snippet?
```c
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
```
a. 4
b. 5
c. 6
d. Compiler Error
6. Which of the following is a correct way to define a constant macro in C?
a. #define MAX_VALUE 100
b. const MAX_VALUE = 100;
c. const int MAX_VALUE = 100;
d. int MAX_VALUE = 100;
7. What does the "sizeof" operator return in C?
a. The size of a variable in bytes.
b. The address of a variable.
c. The value of a variable.
d. The data type of a variable.
8. What is the scope of a variable declared inside a function in C?
a. Global scope
b. Local scope
c. Function scope
d. Block scope
9. What does the "fgets" function in C do?
a. Reads a line of text from the standard input.
b. Converts a string to lowercase.
c. Concatenates two strings.
d. Reverses a string.
10. Which header file should be included to use the malloc and free functions in C?
a. stdio.h
b. math.h
c. string.h
d. stdlib.h
11. Which of the following is not a basic data type in C?
a) int
b) float
c) string
d) char
12. What is the size of the "int" data type in C?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) It depends on the system architecture.
13. Which operator is used to access the value at the address stored in a pointer variable?
a) &
b) *
c) $
d) #
14. What is the output of the following code snippet?
```c
printf("%d", sizeof('a'));
```
a) 1
b) 2
c) 4
d) It depends on the system architecture.
15. In C, what is the maximum number of arguments that a function can take?
a) 128
b) 256
c) It depends on the compiler.
d) There is no fixed limit.
16. Which header file must be included to use the "malloc" and "free" functions in C?
a) stdlib.h
b) malloc.h
c) mem.h
d) alloc.h
17. What is the output of the following code snippet?
```c
int x = 5;
int y = ++x + x++;
printf("%d", y);
```
a) 10
b) 11
c) 12
d) It is undefined behavior.
18. Which keyword is used to define a constant in C?
a) const
b) constant
c) constexpr
d) #define
19. What is the purpose of the "break" statement in C?
a) To terminate a loop or switch statement.
b) To skip the current iteration of a loop.
c) To jump to a specific label within a function.
d) To exit the program completely.
20. What is the correct way to declare a function that takes no arguments in C?
a) void function();
b) void function(void);
c) void function([]);
d) void function(...);
21. What is the correct way to declare a constant variable in C?
a) const int x;
b) final int x;
c) static int x;
d) readonly int x;
22. What is the output of the following code snippet?
```c
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++ + ++x);
return 0;
}
```
a) 11
b) 12
c) 13
d) 14
23. Which of the following is not a valid data type in C?
a) long long
b) float
c) boolean
d) char
24. What is the purpose of the "break" statement in a switch statement?
a) It terminates the program execution.
b) It skips the current iteration of a loop.
c) It transfers control to the next case label.
d) It exits the switch statement and transfers control to the statement after the switch.
25. Which operator is used to access the value stored in a pointer variable in C?
a) *
b) &
c) ->
d) |
26. What will be the output of the following code?
```c
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf("%d", sizeof(arr) / sizeof(arr[0]));
return 0;
}
```
a) 5
b) 4
c) 1
d) 0
27. What is the purpose of the "sizeof" operator in C?
a) It calculates the size of a data type or variable in bytes.
b) It calculates the square root of a number.
c) It performs bitwise operations on integers.
d) It returns the ASCII value of a character.
28. What is the correct way to declare a function in C?
a) void function(int a);
b) int function(a);
c) function(int a);
d) void function(a);
29. What is the correct way to allocate memory for an array dynamically in C?
a) int arr[10];
b) int* arr = (int*) malloc(10 * sizeof(int));
c) int* arr = malloc(10 * sizeof(int));
d) int* arr = new int[10];
30. Which of the following statements is true regarding the "volatile" keyword in C?
a) It indicates that a variable should not be modified.
b) It ensures that the variable is initialized to 0.
c) It indicates that a variable's value may change unexpectedly.
d) It specifies that a variable is a constant.
Certainly! Here are some multiple-choice questions (MCQs) related to the C programming language:
31. Which of the following is the correct syntax for declaring a variable in C?
a) int x;
b) x = 10;
c) declare x as integer;
d) variable x;
32. What is the output of the following code snippet?
```c
printf("%d", sizeof(int));
```
a) 1
b) 2
c) 4
d) 8
33. What is the value of the variable "result" after executing the following code snippet?
```c
int a = 10;
int b = 3;
int result = a % b;
```
a) 3
b) 0
c) 1
d) 10
34. Which of the following is NOT a valid data type in C?
a) float
b) string
c) char
d) double
35. What is the output of the following code snippet?
```c
int i = 5;
printf("%d", i++);
```
a) 5
b) 6
c) 4
d) 0
36. Which of the following is the correct way to define a constant in C?
a) const int MAX_VALUE = 100;
b) #define MAX_VALUE 100
c) constant MAX_VALUE = 100;
d) int MAX_VALUE = 100;
37. What is the output of the following code snippet?
```c
int x = 5;
int y = 10;
printf("%d", x > y ? x : y);
```
a) 5
b) 10
c) 15
d) Compiler error
38. What does the "sizeof" operator return in C?
a) The size of a variable in bytes
b) The value of a variable
c) The address of a variable
d) The data type of a variable
39. How do you comment a single line in C?
a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <!-- This is a comment -->
40. What is the purpose of the "break" statement in a switch statement?
a) It terminates the loop.
b) It exits the current case and continues execution from the next case.
c) It skips the current iteration of a loop.
d) It restarts the loop from the beginning.
41. Which of the following is not a valid data type in C?
a) float
b) string
c) char
d) int
42. What is the size of the "int" data type in C?
a) 4 bytes
b) 2 bytes
c) 8 bytes
d) It varies depending on the system
43. Which of the following is used to indicate the end of a statement in C?
a) Period (.)
b) Semicolon (;)
c) Comma (,)
d) Colon (:)
44. Which of the following is used to declare a variable in C?
a) int
b) var
c) declare
d) variable
45. What is the output of the following code snippet?
```
int x = 5;
printf("%d", x++);
```
a) 4
b) 5
c) 6
d) It will result in an error
46. What is the correct syntax to access the nth element of an array in C?
a) array(n)
b) array[n]
c) array.n
d) array-n
47. What is the purpose of the "sizeof" operator in C?
a) It calculates the size of a variable or data type in bytes
b) It returns the address of a variable
c) It converts a variable to a different data type
d) It calculates the sum of two variables
48. Which of the following is not a valid way to initialize an array in C?
a) int arr[] = {1, 2, 3};
b) int arr[3] = {1, 2, 3};
c) int arr[3] = {1, 2};
d) int arr[3] = {1};
49. What is the output of the following code snippet?
```
char str[] = "Hello";
printf("%s", str + 2);
```
a) Hello
b) lo
c) llo
d) It will result in an error
50. Which of the following loop constructs is used for definite iteration in C?
a) for loop
b) while loop
c) do-while loop
d) All of the above
51. Which of the following is not a valid data type in C?
a) int
b) float
c) double
d) decimal
52. What is the size of the "int" data type in bytes?
a) 2
b) 4
c) 8
d) It depends on the system architecture.
53. What is the correct syntax for declaring a pointer variable in C?
a) int *ptr;
b) int ptr;
c) *int ptr;
d) ptr int;
54. What is the output of the following code snippet?
```c
printf("%d", sizeof(3.14));
```
a) 4
b) 8
c) 16
d) It depends on the system architecture.
55. What is the purpose of the "break" statement in C?
a) To exit the current loop or switch statement.
b) To skip the current iteration of a loop.
c) To divide a program into smaller modules.
d) To terminate the program.
56. What is the output of the following code snippet?
```c
int x = 5;
int y = x++;
printf("%d %d", x, y);
```
a) 5 5
b) 5 6
c) 6 6
d) 6 5
57. What is the correct way to allocate memory for an array dynamically in C?
a) int arr[10];
b) int *arr = malloc(10 * sizeof(int));
c) int arr[] = {1, 2, 3, 4, 5};
d) int *arr = new int[10];
58. What is the output of the following code snippet?
```c
int i;
for (i = 0; i < 5; i++) {
printf("%d ", i);
}
```
a) 0 1 2 3 4
b) 1 2 3 4 5
c) 0 1 2 3
d) 1 2 3 4
59. What is the correct way to include a header file in a C program?
a) #include <stdio.h>
b) #include "stdio.h"
c) #include <"stdio.h">
d) #import <stdio.h>
60. What is the output of the following code snippet?
```c
int x = 10;
int *ptr = &x;
printf("%d", *ptr);
```
a) 10
b) 0
c) Garbage value
d) Compiler error
Sure! Here are some multiple-choice questions (MCQs) on the C programming language:
61. Which of the following is not a valid data type in C?
a) int
b) float
c) double
d) decimal
62. What is the size of the "int" data type in bytes?
a) 2
b) 4
c) 8
d) It depends on the system architecture.
63. What is the correct syntax for declaring a pointer variable in C?
a) int *ptr;
b) int ptr;
c) *int ptr;
d) ptr int;
64. What is the output of the following code snippet?
```c
printf("%d", sizeof(3.14));
```
a) 4
b) 8
c) 16
d) It depends on the system architecture.
65. What is the purpose of the "break" statement in C?
a) To exit the current loop or switch statement.
b) To skip the current iteration of a loop.
c) To divide a program into smaller modules.
d) To terminate the program.
66. What is the output of the following code snippet?
```c
int x = 5;
int y = x++;
printf("%d %d", x, y);
```
a) 5 5
b) 5 6
c) 6 6
d) 6 5
67. What is the correct way to allocate memory for an array dynamically in C?
a) int arr[10];
b) int *arr = malloc(10 * sizeof(int));
c) int arr[] = {1, 2, 3, 4, 5};
d) int *arr = new int[10];
68. What is the output of the following code snippet?
```c
int i;
for (i = 0; i < 5; i++) {
printf("%d ", i);
}
```
a) 0 1 2 3 4
b) 1 2 3 4 5
c) 0 1 2 3
d) 1 2 3 4
69. What is the correct way to include a header file in a C program?
a) #include <stdio.h>
b) #include "stdio.h"
c) #include <"stdio.h">
d) #import <stdio.h>
70. What is the output of the following code snippet?
```c
int x = 10;
int *ptr = &x;
printf("%d", *ptr);
```
a) 10
b) 0
c) Garbage value
d) Compiler error
71. Which of the following is not a fundamental data type in C?
a) int
b) float
c) string
d) char
72. What is the correct way to declare a constant in C?
a) constant int x = 5;
b) const x = 5;
c) const int x = 5;
d) int const x = 5;
73. What is the output of the following code snippet?
```c
int x = 5;
printf("%d", ++x);
```
a) 5
b) 6
c) 10
d) Compiler error
74. Which of the following is an invalid identifier in C?
a) my_variable
b) _myVariable
c) 123myVariable
d) MyVariable123
75. How do you access the first element of an array in C?
a) array[0]
b) array[1]
c) array[-1]
d) array[first]
76. What is the purpose of the "sizeof" operator in C?
a) It calculates the size of a data type or variable in bytes.
b) It converts a variable to a different data type.
c) It performs arithmetic operations on variables.
d) It returns the address of a variable.
77. What is the correct syntax for a while loop in C?
a) while (condition) { // code }
b) while { // code } (condition)
c) (condition) while { // code }
d) (condition) { // code } while
78. What is the output of the following code snippet?
code
```c
int i = 0;
for (; i < 5; i++) {
if (i == 2) {
break;
}
printf("%d ", i);
}
```
a) 0 1
b) 0 1 2
c) 0 1 2 3 4
d) 1 2 3 4 5
79. What does the "return" statement do in a function?
a) Exits the program
b) Jumps to the next line of code
c) Returns a value from the function
d) Declares a variable
80. What is the purpose of the "malloc" function in C?
a) Allocates memory for a variable
b) Releases memory used by a variable
c) Copies the contents of one variable to another
d) Performs mathematical calculations
Sure, here are some multiple-choice questions (MCQs) related to the C programming language:
81. Which of the following is not a valid C variable name?
a) myVar
b) _myVar
c) 1var
d) VAR
82. Which operator is used to access the value at a specific memory address in C?
a) *
b) &
c) %
d) #
83. What is the output of the following code snippet?
```c
int x = 10;
printf("%d", x++);
```
a) 10
b) 11
c) 9
d) Compilation error
84. What is the purpose of the `sizeof` operator in C?
a) It returns the size of a variable or data type in bytes.
b) It returns the memory address of a variable.
c) It returns the ASCII value of a character.
d) It returns the remainder of a division operation.
85. What is the correct syntax to declare a function in C?
a) int functionName()
b) functionName()
c) void functionName()
d) functionName(void)
86. Which loop is guaranteed to execute at least once in C?
a) for loop
b) while loop
c) do-while loop
d) switch statement
87. What is the purpose of the `break` statement in C?
a) It terminates the execution of the current loop or switch statement.
b) It skips the current iteration of a loop and continues with the next iteration.
c) It returns a value from a function.
d) It performs bitwise operations on operands.
88. What is the output of the following code snippet?
```c
int i;
for (i = 0; i < 5; i++) {
if (i == 3)
continue;
printf("%d ", i);
}
```
a) 0 1 2 4
b) 0 1 2 3 4
c) 0 1 2
d) Compilation error
89. How would you declare a two-dimensional array in C?
a) int arr[][]
b) int arr[][]
c) int arr[][]
d) int arr[][]
90. What is the scope of a variable declared inside a function in C?
a) Global scope
b) Local scope
c) Static scope
d) Constant scope
Sure! Here are some multiple-choice questions (MCQs) related to the C programming language:
91. What is the correct syntax for declaring a variable in C?
a) int x;
b) x = int;
c) int = x;
d) x int;
92. Which of the following is not a valid data type in C?
a) float
b) boolean
c) char
d) double
93. What is the output of the following code snippet?
```c
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++);
return 0;
}
```
a) 5
b) 6
c) 4
d) Compiler error
94. What is the result of the expression `10 / 3` in C?
a) 3.33
b) 3
c) 3.0
d) 3.3333
95. Which of the following is the correct way to declare a function in C?
a) int function(int x);
b) function(int x) int;
c) function x int;
d) x int function;
96. What is the purpose of the `sizeof` operator in C?
a) It calculates the sum of two numbers.
b) It calculates the average of a set of numbers.
c) It determines the size (in bytes) of a data type or variable.
d) It checks if two values are equal.
97. Which symbol is used for the logical OR operator in C?
a) &&
b) !
c) ||
d) |
98. What is the correct way to allocate memory dynamically in C?
a) int x = malloc(sizeof(int));
b) int* x = malloc(int);
c) int* x = malloc(sizeof(int));
d) malloc(int* x, sizeof(int));
99. Which keyword is used to terminate a loop in C?
a) break
b) exit
c) return
d) terminate
100. What is the output of the following code snippet?
```c
#include <stdio.h>
int main() {
int x = 10;
if (x > 5) {
printf("Hello");
} else {
printf("Goodbye");
}
return 0;
}
```
a) Hello
b) Goodbye
c) 10
d) Compiler error
Answers:
1. c
2. a
3. a
4. a
5. b
6. a
7. a
8. b
9. a
10. d
11. c) string
12. d) It depends on the system architecture.
13. b) *
14. a) 1
15. c) It depends on the compiler.
16. a) stdlib.h
17. d) It is undefined behavior.
18. a) const
19. a) To terminate a loop or switch statement.
20. b) void function(void);
21. a) const int x;
22. d) 14
23. c) boolean
24. c) It transfers control to the next case label.
25. a) *
26. a) 5
27. a) It calculates the size of a data type or variable in bytes.
28. a) void function(int a);
29. c) int* arr = malloc(10 * sizeof(int));
30. c) It indicates that a variable's value may change unexpectedly.
31. a) int x;
32. c) 4
33. c) 1
34. b) string
35. a) 5
36. a) const int MAX_VALUE = 100;
37. b) 10
38. a) The size of a variable in bytes
39. a) // This is a comment
40. b) It exits the current case and continues execution from the next case.
41. b) string
42. d) It varies depending on the system
43. b) Semicolon (;)
44. a) int
45. b) 5
46. b) array[n]
47. a) It calculates the size of a variable or data type in bytes
48. c) int arr[3] = {1, 2};
49. c) llo
50. a) for loop
51. d) decimal
52. d) It depends on the system architecture.
53. a) int *ptr;
54. d) It depends on the system architecture.
55. a) To exit the current loop or switch statement.
56. d) 6 5
57. b) int *arr = malloc(10 * sizeof(int));
58. a) 0 1 2 3 4
59. a) #include <stdio.h>
60. a) 10
61. d) decimal
62. d) It depends on the system architecture.
63. a) int *ptr;
64. d) It depends on the system architecture.
65. a) To exit the current loop or switch statement.
66. d) 6 5
67. b) int *arr = malloc(10 * sizeof(int));
68. a) 0 1 2 3 4
69. a) #include <stdio.h>
70. a) 10
71. c) string
72. c) const int x = 5;
73. b) 6
74. c) 123myVariable
75. a) array[0]
76. a) It calculates the size of a data type or variable in bytes.
77. a) while (condition) { // code }
78. a) 0 1
79. c) Returns a value from the function
80. a) Allocates memory for a variable
81. c) 1var
82. a) *
83. b) 11
84. a) It returns the size of a variable or data type in bytes.
85. d) functionName(void)
86. c) do-while loop
87. a) It terminates the execution of the current loop or switch statement.
88. a) 0 1 2 4
89. d) int arr[][]
90. b) Local scope
91. a) int x;
92. b) boolean
93. a) 5
94. b) 3
95. a) int function(int x);
96. c) It determines the size (in bytes) of a data type or variable.
97. c) ||
98. c) int* x = malloc(sizeof(int));
99. a) break
100. a) Hello.
0 Comments