Are you ready to test your knowledge and deepen your understanding of C programming? Look no further! In this blog post, we present 100 multiple-choice questions and answers that cover various concepts and aspects of the C programming language. Whether you are a beginner looking to solidify your foundation or an experienced programmer seeking to brush up on your skills, this comprehensive compilation of questions will put your C programming prowess to the test.
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
1. Which of the following is NOT a valid variable name in C? | a123 | _foo | float | hello_world | float |
2. What is the value of the expression 3 + 4 * 5 - 6 / 2 in C? | 23 | 25 | 21 | 22 | 25 |
3. What is the correct syntax for declaring a pointer variable in C? | int ptr = &x; | int *ptr = &x; | int ptr = x; | int &ptr = x; | int *ptr = &x; |
4. Which of the following is NOT a valid way to initialize an array in C? | int arr[] = {1, 2, 3}; | int arr[3] = {1, 2, 3}; | int arr[3] = {1}; | int arr[3] = {}; | int arr[3] = {}; |
5. Which of the following is the correct way to include a header file in C? | #include <stdio.h> | #include "stdio.h" | #include <"stdio.h"> | #include "stdio" | #include <stdio.h> |
6. What is the purpose of the sizeof operator in C? | To determine the size of a variable or data type in bytes | To calculate the sum of two numbers | To compare two variables for equality | To assign a value to a variable | |
7. Which of the following is NOT a valid data type in C? | float | boolean | char | long long | boolean |
8. What is the correct way to write a single-line comment in C? | // This is a comment | /* This is a comment */ | # This is a comment | -- This is a comment | // This is a comment |
9. Which keyword is used to exit from a loop in C? | break | continue | return | exit | break |
10. What does the & operator do in C? | It returns the address of a variable | It performs bitwise AND operation | It multiplies two numbers | It checks for equality between two variables | It returns the address of a variable |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
11. How do you declare a function in C without specifying a return type? | void functionName(parameters); | returnType functionName(parameters); | functionName(parameters); | int functionName(parameters); | returnType functionName(parameters); |
12. Which header file should be included to use the strlen() function in C? | <stdlib.h> | <string.h> | <stdio.h> | <math.h> | <string.h> |
13. What is the result of the expression 5 / 2 in C? | 2.5 | 2 | 2.0 | 2.25 | 2 |
14. Which of the following is the correct way to define a constant in C? | constant int MAX_VALUE = 100; | const MAX_VALUE = 100; | #define MAX_VALUE 100 | constant MAX_VALUE = 100; | #define MAX_VALUE 100 |
15. What is the purpose of the fgets() function in C? | To read a line of text from a file | To calculate the square root of a number | To format a string | To allocate memory dynamically | To read a line of text from a file |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
16. Which of the following is NOT a valid loop structure in C? | for | loop | while | do-while | loop |
17. What is the output of the following code snippet in C? <br> int x = 5; <br> int y = x++; <br> printf("%d %d\n", x, y); | 5 5 | 5 6 | 6 5 | 6 6 | 6 5 |
18. What is the correct syntax for the switch statement in C? | case constant: statements | if (condition) { statements } | switch (expression) { case constant: statements } | for (initialization; condition; increment) { statements } | switch (expression) { case constant: statements } |
19. Which of the following is the correct way to allocate dynamic memory in C? | malloc(size_t size) | calloc(size_t num, size_t size) | free(ptr) | realloc(ptr, size_t size) | malloc(size_t size) |
20. What is the purpose of the strcpy() function in C? | To copy a string from one variable to another | To compare two strings for equality | To convert a string to uppercase | To calculate the length of a string | To copy a string from one variable to another |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
21. What is the purpose of the typedef keyword in C? | To create a new data type alias | To define a constant value | To declare a function prototype | To perform arithmetic operations | To create a new data type alias |
22. Which of the following is the correct way to open a file in C for writing? | fopen("file.txt", "r") | fopen("file.txt", "w") | fopen("file.txt", "a") | fopen("file.txt", "x") | fopen("file.txt", "w") |
23. How do you access the value stored at a specific memory location in C? | Using the * (indirection) operator | Using the . (dot) operator | Using the > (arrow) operator | Using the = (assignment) operator | Using the * (indirection) operator |
24. What is the result of the expression sizeof("Hello") in C? | 5 | 6 | 7 | 8 | 6 |
25. Which of the following functions is used to convert a string to a double in C? | atoi() | atof() | itoa() | sprintf() | atof() |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
26. What is the purpose of the strcat() function in C? | To concatenate two strings | To compare two strings | To copy a string from one variable to another | To calculate the length of a string | To concatenate two strings |
27. Which of the following is NOT a valid storage class specifier in C? | auto | register | static | dynamic | dynamic |
28. What is the output of the following code snippet in C? <br> int arr[5] = {1, 2, 3, 4, 5}; <br> printf("%d\n", arr[3]); | 1 | 2 | 3 | 4 | 4 |
29. What is the correct way to close a file in C using the fclose() function? | close(file); | close(file.txt); | fclose(file); | fclose(file.txt); | fclose(file); |
30. Which of the following is the correct way to declare a multidimensional array in C? | int arr[3][3]; | int arr[3,3]; | int arr[3,3]; | int arr[3][3]; | int arr[3][3]; |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
31. Which of the following is NOT a valid variable type in C? | float | boolean | string | double | string |
32. How do you declare a constant in C? | const int CONSTANT = 10; | constant CONSTANT = 10; | #define CONSTANT 10 | int CONSTANT = 10; | const int CONSTANT = 10; |
33. What is the purpose of the break statement in C? | To exit a loop or switch statement | To skip the current iteration of a loop | To divide two numbers | To print a message to the console | To exit a loop or switch statement |
34. Which of the following is NOT a valid way to comment a single line in C? | // This is a comment | # This is a comment | /* This is a comment */ | ; This is a comment | # This is a comment |
35. How do you access the address of a variable in C? | Using the * (indirection) operator | Using the . (dot) operator | Using the & (address-of) operator | Using the = (assignment) operator | Using the & (address-of) operator |
36. What is the purpose of the sizeof operator in C? | To determine the size of a variable or data type in bytes | To perform arithmetic operations | To compare two variables for equality | To assign a value to a variable | To determine the size of a variable or data type in bytes |
37. Which of the following is NOT a valid arithmetic operator in C? | ^ (Exponentiation) | * (Multiplication) | / (Division) | + (Addition) | ^ (Exponentiation) |
38. What is the correct syntax for a function declaration in C? | int functionName(int a, int b); | functionName(int a, int b) int; | functionName(int a, b int) int; | int functionName(a, b); | int functionName(int a, int b); |
39. Which of the following is the correct way to include a standard library header file in C? | #include <stdio.h> | #include "stdio.h" | #include <"stdio.h"> | #include "stdio" | #include <stdio.h> |
40. What is the purpose of the while loop in C? | To repeatedly execute a block of code while a condition is true | To iterate over a block of code a fixed number of times | To execute a block of code at least once, even if the condition is false | To jump to a specific section of code | To repeatedly execute a block of code while a condition is true |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
41. What is the purpose of the do-while loop in C? | To repeatedly execute a block of code until a condition is false | To execute a block of code a fixed number of times | To jump to a specific section of code | To conditionally execute a block of code | To repeatedly execute a block of code until a condition is false |
42. Which of the following is the correct way to declare a pointer variable in C? | int ptr; | int* ptr; | ptr int; | pointer int; | int* ptr; |
43. What is the purpose of the scanf() function in C? | To read input from the user | To print output to the console | To perform mathematical calculations | To compare two strings | To read input from the user |
44. Which of the following is NOT a valid relational operator in C? | == (Equal to) | != (Not equal to) | (Logical OR) | ||
45. What is the purpose of the return statement in a function in C? | To exit the function and return a value to the caller | To print a message to the console | To skip the current iteration of a loop | To divide two numbers | To exit the function and return a value to the caller |
46. Which of the following is the correct way to initialize an array in C? | int arr[5] = {1, 2, 3, 4, 5}; | int arr[] = {1, 2, 3, 4, 5}; | int arr[5]; arr = {1, 2, 3, 4, 5}; | int arr[5] = [1, 2, 3, 4, 5]; | int arr[] = {1, 2, 3, 4, 5}; |
47. What is the purpose of the continue statement in C? | To skip the current iteration of a loop and continue with the next iteration | To exit a loop or switch statement | To divide two numbers | To print a message to the console | To skip the current iteration of a loop and continue with the next iteration |
48. Which of the following is NOT a valid logical operator in C? | & (Bitwise AND) | (Bitwise OR) | ! (Logical NOT) | ||
49. What is the purpose of the getchar() function in C? | To read a single character from the console | To compare two strings | To perform mathematical calculations | To print output to the console | To read a single character from the console |
50. Which of the following is the correct way to declare a constant pointer in C? | int * const ptr; | const int * ptr; | const int * const ptr; | int const * ptr; | const int * const ptr; |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
51. What is the purpose of the union in C? | To define a data type that can hold different types of data | To define a constant value | To declare a function prototype | To perform arithmetic operations | To define a data type that can hold different types of data |
52. Which of the following is NOT a valid bitwise operator in C? | & (Bitwise AND) | (Bitwise OR) | ^ (Bitwise XOR) | ^ (Bitwise XOR) | |
53. What is the purpose of the strlen() function in C? | To determine the length of a string | To compare two strings | To copy a string from one variable to another | To perform mathematical calculations | To determine the length of a string |
54. Which of the following is the correct way to define a macro in C using the #define directive? | #define MAX_VALUE = 100 | #define MAX_VALUE 100 | #define MAX_VALUE: 100 | #define MAX_VALUE "100" | #define MAX_VALUE 100 |
55. What is the purpose of the NULL macro in C? | To represent a null pointer | To terminate a string | To define a constant value | To exit a loop or switch statement | To represent a null pointer |
56. Which of the following is the correct way to declare a global variable in C? | Inside a function, before any executable statements | Inside a structure definition | Outside of any function, before any executable statements | Inside a loop | Outside of any function, before any executable statements |
57. What is the purpose of the volatile keyword in C? | To indicate that a variable may be modified by external factors | To indicate that a variable cannot be modified | To define a constant value | To perform arithmetic operations | To indicate that a variable may be modified by external factors |
58. Which of the following is NOT a valid control structure in C? | if-else | switch | goto | continue | continue |
59. What is the purpose of the fgets() function in C? | To read a string from a file | To write a string to a file | To compare two strings | To perform mathematical calculations | To read a string from a file |
60. Which of the following is the correct way to declare a constant string in C? | const char* str = "Hello"; | char* const str = "Hello"; | const char[6] str = "Hello"; | char const* str = "Hello"; | const char* str = "Hello"; |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
61. What is the purpose of the typedef keyword in C? | To create an alias for an existing data type | To define a constant value | To declare a function prototype | To perform mathematical calculations | To create an alias for an existing data type |
62. Which of the following is NOT a valid loop in C? | for loop | while loop | do-while loop | repeat loop | repeat loop |
63. What is the purpose of the malloc() function in C? | To dynamically allocate memory | To deallocate memory | To copy a string from one variable to another | To print output to the console | To dynamically allocate memory |
64. Which of the following is the correct way to access an element in a 2D array in C? | array[row][column] | array(column, row) | array[row, column] | array(column)(row) | array[row][column] |
65. What is the purpose of the void keyword in C? | To indicate that a function does not return a value | To declare a variable without a type | To perform type casting | To specify the size of a data type | To indicate that a function does not return a value |
66. Which of the following is the correct way to declare a constant integer in C? | const int NUMBER = 10; | int const NUMBER = 10; | NUMBER int = 10; | int NUMBER = 10; | const int NUMBER = 10; |
67. What is the purpose of the fwrite() function in C? | To write data to a file | To read data from a file | To compare two strings | To perform mathematical calculations | To write data to a file |
68. Which of the following is NOT a valid C programming data type? | boolean | char | float | long | boolean |
69. What is the purpose of the static keyword in C? | To define a variable with static storage duration | To make a variable accessible only within its block of code | To define a constant value | To perform bitwise operations | To define a variable with static storage duration |
70. Which of the following is the correct way to declare a constant structure in C? | const struct MyStruct { int x; float y; }; | struct const MyStruct { int x; float y; }; | const MyStruct { int x; float y; }; | MyStruct const { int x; float y; }; | const struct MyStruct { int x; float y; }; |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
71. What is the purpose of the enum in C? | To define a set of named constants | To declare a function prototype | To allocate memory dynamically | To perform mathematical calculations | To define a set of named constants |
72. Which of the following is NOT a valid storage class specifier in C? | local | auto | static | register | local |
73. What is the purpose of the strcpy() function in C? | To copy a string from one variable to another | To compare two strings | To read a string from a file | To perform mathematical calculations | To copy a string from one variable to another |
74. Which of the following is the correct way to declare a constant character in C? | const char ch = 'A'; | char const ch = 'A'; | ch char = 'A'; | char ch = 'A'; | const char ch = 'A'; |
75. What is the purpose of the sizeof operator in C when used with the sizeof(variable) syntax? | To determine the size of a variable in bytes | To perform arithmetic operations | To compare two variables for equality | To assign a value to a variable | To determine the size of a variable in bytes |
76. Which of the following is NOT a valid logical operator in C? | & (Logical AND) | (Logical OR) | ! (Logical NOT) | ||
77. What is the purpose of the strcat() function in C? | To concatenate two strings | To convert a string to uppercase | To reverse a string | To perform mathematical calculations | To concatenate two strings |
78. Which of the following is the correct way to declare a constant pointer to a constant integer in C? | const int * const ptr; | const int * ptr; | int * const ptr; | int const * ptr; | const int * const ptr; |
79. What is the purpose of the memcmp() function in C? | To compare two blocks of memory | To read input from the user | To write output to a file | To perform mathematical calculations | To compare two blocks of memory |
80. Which of the following is the correct way to declare a constant union in C? | const union MyUnion { int x; float y; }; | union const MyUnion { int x; float y; }; | const MyUnion { int x; float y; }; | MyUnion const { int x; float y; }; | const union MyUnion { int x; float y; }; |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
81. What is the purpose of the break statement in C? | To exit a loop or switch statement | To skip the current iteration of a loop | To divide two numbers | To print output to the console | To exit a loop or switch statement |
82. Which of the following is NOT a valid arithmetic operator in C? | % (Modulus) | * (Multiplication) | ^ (Exponentiation) | – (Subtraction) | ^ (Exponentiation) |
83. What is the purpose of the strcpy() function in C? | To copy a string from one variable to another | To compare two strings | To perform mathematical calculations | To read a string from a file | To copy a string from one variable to another |
84. Which of the following is the correct way to declare a constant float in C? | const float PI = 3.14159; | float const PI = 3.14159; | PI const = 3.14159; | float PI = 3.14159; | const float PI = 3.14159; |
85. What is the purpose of the sizeof operator in C when used with the sizeof(type) syntax? | To determine the size of a data type in bytes | To perform arithmetic operations | To compare two variables for equality | To assign a value to a variable | To determine the size of a data type in bytes |
86. Which of the following is NOT a valid relational operator in C? | == (Equal to) | != (Not equal to) | >< (Comparison) | < (Less than) | >< (Comparison) |
87. What is the purpose of the strncat() function in C? | To concatenate a specified number of characters from one string to another | To convert a string to lowercase | To reverse a string | To perform mathematical calculations | To concatenate a specified number of characters from one string to another |
88. Which of the following is the correct way to declare a constant pointer to a constant character in C? | const char * const ptr; | const char * ptr; | char * const ptr; | char const * ptr; | const char * const ptr; |
89. What is the purpose of the memcmp() function in C? | To compare two blocks of memory | To read a single character from the console | To write output to a file | To perform mathematical calculations | To compare two blocks of memory |
90. Which of the following is the correct way to declare a constant typedef in C? | typedef const int MyType; | const typedef int MyType; | typedef int const MyType; | int typedef const MyType; | typedef const int MyType; |
Question | Option A | Option B | Option C | Option D | Answer |
---|---|---|---|---|---|
91. What is the purpose of the continue statement in C? | To skip the current iteration of a loop and continue with the next iteration | To exit a loop or switch statement | To divide two numbers | To print output to the console | To skip the current iteration of a loop and continue with the next iteration |
92. Which of the following is NOT a valid assignment operator in C? | @= (At Assignment) | += (Addition Assignment) | -= (Subtraction Assignment) | *= (Multiplication Assignment) | @= (At Assignment) |
93. What is the purpose of the strncpy() function in C? | To copy a specified number of characters from one string to another | To compare two strings | To perform mathematical calculations | To read a string from a file | To copy a specified number of characters from one string to another |
94. Which of the following is the correct way to declare a constant double in C? | const double PI = 3.14159; | double const PI = 3.14159; | PI double = 3.14159; | double PI = 3.14159; | const double PI = 3.14159; |
95. What is the purpose of the sizeof operator in C when used with the sizeof(expression) syntax? | To determine the size of an expression in bytes | To perform arithmetic operations | To compare two variables for equality | To assign a value to a variable | To determine the size of an expression in bytes |
96. Which of the following is NOT a valid logical operator in C? | && (Logical AND) | (Logical OR) | |||
97. What is the purpose of the strtok() function in C? | To tokenize a string into smaller parts based on a delimiter | To convert a string to uppercase | To reverse a string | To perform mathematical calculations | To tokenize a string into smaller parts based on a delimiter |
98. Which of the following is the correct way to declare a constant pointer to a character in C? | const char *ptr; | char *const ptr; | char const *ptr; | ptr const char; | const char *ptr; |
99. What is the purpose of the memset() function in C? | To fill a block of memory with a specified value | To read input from the user | To write output to a file | To perform mathematical calculations | To fill a block of memory with a specified value |
100. Which of the following is the correct way to declare a constant typedef pointer in C? | typedef int *const MyType; | const typedef int *MyType; | typedef const int *MyType; | int *const typedef MyType; | typedef const int *MyType; |