HomeInterview Q&A100 Multiple Choice Questions & Answers on C Programming

100 Multiple Choice Questions & Answers on C Programming

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.

QuestionOption AOption BOption COption DAnswer
1. Which of the following is NOT a valid variable name in C?a123_foofloathello_worldfloat
2. What is the value of the expression 3 + 4 * 5 - 6 / 2 in C?2325212225
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 bytesTo calculate the sum of two numbersTo compare two variables for equalityTo assign a value to a variable
7. Which of the following is NOT a valid data type in C?floatbooleancharlong longboolean
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?breakcontinuereturnexitbreak
10. What does the & operator do in C?It returns the address of a variableIt performs bitwise AND operationIt multiplies two numbersIt checks for equality between two variablesIt returns the address of a variable
QuestionOption AOption BOption COption DAnswer
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.522.02.252
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 100constant 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 fileTo calculate the square root of a numberTo format a stringTo allocate memory dynamicallyTo read a line of text from a file
QuestionOption AOption BOption COption DAnswer
16. Which of the following is NOT a valid loop structure in C?forloopwhiledo-whileloop
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 55 66 56 66 5
18. What is the correct syntax for the switch statement in C?case constant: statementsif (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 anotherTo compare two strings for equalityTo convert a string to uppercaseTo calculate the length of a stringTo copy a string from one variable to another
QuestionOption AOption BOption COption DAnswer
21. What is the purpose of the typedef keyword in C?To create a new data type aliasTo define a constant valueTo declare a function prototypeTo perform arithmetic operationsTo 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) operatorUsing the . (dot) operatorUsing the > (arrow) operatorUsing the = (assignment) operatorUsing the * (indirection) operator
24. What is the result of the expression sizeof("Hello") in C?56786
25. Which of the following functions is used to convert a string to a double in C?atoi()atof()itoa()sprintf()atof()
QuestionOption AOption BOption COption DAnswer
26. What is the purpose of the strcat() function in C?To concatenate two stringsTo compare two stringsTo copy a string from one variable to anotherTo calculate the length of a stringTo concatenate two strings
27. Which of the following is NOT a valid storage class specifier in C?autoregisterstaticdynamicdynamic
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]);12344
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];
QuestionOption AOption BOption COption DAnswer
31. Which of the following is NOT a valid variable type in C?floatbooleanstringdoublestring
32. How do you declare a constant in C?const int CONSTANT = 10;constant CONSTANT = 10;#define CONSTANT 10int CONSTANT = 10;const int CONSTANT = 10;
33. What is the purpose of the break statement in C?To exit a loop or switch statementTo skip the current iteration of a loopTo divide two numbersTo print a message to the consoleTo 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) operatorUsing the . (dot) operatorUsing the & (address-of) operatorUsing the = (assignment) operatorUsing 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 bytesTo perform arithmetic operationsTo compare two variables for equalityTo assign a value to a variableTo 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 trueTo iterate over a block of code a fixed number of timesTo execute a block of code at least once, even if the condition is falseTo jump to a specific section of codeTo repeatedly execute a block of code while a condition is true
QuestionOption AOption BOption COption DAnswer
41. What is the purpose of the do-while loop in C?To repeatedly execute a block of code until a condition is falseTo execute a block of code a fixed number of timesTo jump to a specific section of codeTo conditionally execute a block of codeTo 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 userTo print output to the consoleTo perform mathematical calculationsTo compare two stringsTo 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 callerTo print a message to the consoleTo skip the current iteration of a loopTo divide two numbersTo 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 iterationTo exit a loop or switch statementTo divide two numbersTo print a message to the consoleTo 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 consoleTo compare two stringsTo perform mathematical calculationsTo print output to the consoleTo 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;
QuestionOption AOption BOption COption DAnswer
51. What is the purpose of the union in C?To define a data type that can hold different types of dataTo define a constant valueTo declare a function prototypeTo perform arithmetic operationsTo 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 stringTo compare two stringsTo copy a string from one variable to anotherTo perform mathematical calculationsTo 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 pointerTo terminate a stringTo define a constant valueTo exit a loop or switch statementTo 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 statementsInside a structure definitionOutside of any function, before any executable statementsInside a loopOutside 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 factorsTo indicate that a variable cannot be modifiedTo define a constant valueTo perform arithmetic operationsTo indicate that a variable may be modified by external factors
58. Which of the following is NOT a valid control structure in C?if-elseswitchgotocontinuecontinue
59. What is the purpose of the fgets() function in C?To read a string from a fileTo write a string to a fileTo compare two stringsTo perform mathematical calculationsTo 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";
QuestionOption AOption BOption COption DAnswer
61. What is the purpose of the typedef keyword in C?To create an alias for an existing data typeTo define a constant valueTo declare a function prototypeTo perform mathematical calculationsTo create an alias for an existing data type
62. Which of the following is NOT a valid loop in C?for loopwhile loopdo-while looprepeat looprepeat loop
63. What is the purpose of the malloc() function in C?To dynamically allocate memoryTo deallocate memoryTo copy a string from one variable to anotherTo print output to the consoleTo 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 valueTo declare a variable without a typeTo perform type castingTo specify the size of a data typeTo 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 fileTo read data from a fileTo compare two stringsTo perform mathematical calculationsTo write data to a file
68. Which of the following is NOT a valid C programming data type?booleancharfloatlongboolean
69. What is the purpose of the static keyword in C?To define a variable with static storage durationTo make a variable accessible only within its block of codeTo define a constant valueTo perform bitwise operationsTo 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; };
QuestionOption AOption BOption COption DAnswer
71. What is the purpose of the enum in C?To define a set of named constantsTo declare a function prototypeTo allocate memory dynamicallyTo perform mathematical calculationsTo define a set of named constants
72. Which of the following is NOT a valid storage class specifier in C?localautostaticregisterlocal
73. What is the purpose of the strcpy() function in C?To copy a string from one variable to anotherTo compare two stringsTo read a string from a fileTo perform mathematical calculationsTo 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 bytesTo perform arithmetic operationsTo compare two variables for equalityTo assign a value to a variableTo 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 stringsTo convert a string to uppercaseTo reverse a stringTo perform mathematical calculationsTo 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 memoryTo read input from the userTo write output to a fileTo perform mathematical calculationsTo 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; };
QuestionOption AOption BOption COption DAnswer
81. What is the purpose of the break statement in C?To exit a loop or switch statementTo skip the current iteration of a loopTo divide two numbersTo print output to the consoleTo 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 anotherTo compare two stringsTo perform mathematical calculationsTo read a string from a fileTo 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 bytesTo perform arithmetic operationsTo compare two variables for equalityTo assign a value to a variableTo 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 anotherTo convert a string to lowercaseTo reverse a stringTo perform mathematical calculationsTo 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 memoryTo read a single character from the consoleTo write output to a fileTo perform mathematical calculationsTo 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;
QuestionOption AOption BOption COption DAnswer
91. What is the purpose of the continue statement in C?To skip the current iteration of a loop and continue with the next iterationTo exit a loop or switch statementTo divide two numbersTo print output to the consoleTo 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 anotherTo compare two stringsTo perform mathematical calculationsTo read a string from a fileTo 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 bytesTo perform arithmetic operationsTo compare two variables for equalityTo assign a value to a variableTo 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 delimiterTo convert a string to uppercaseTo reverse a stringTo perform mathematical calculationsTo 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 valueTo read input from the userTo write output to a fileTo perform mathematical calculationsTo 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;

Share:

Leave a Reply

You May Also Like

Python is a versatile and widely-used programming language known for its simplicity and readability. Whether you’re a beginner or an...
Are you ready to test your knowledge and sharpen your skills in C# programming? Whether you’re a beginner looking to...
Are you ready to test your knowledge of Java? Whether you’re a beginner seeking to solidify your understanding of the...