23
FebC Programs MCQ: For Beginners and Experts
C Programs MCQ is a collection of multiple-choice questions that help you test your knowledge of the C programming language. It includes important topics like variables, loops, arrays, functions, and pointers in C, making it easier to understand the basics. Whether you're getting ready for exams, interviews, or competitive tests, C Programs MCQ is a great way to check and improve your skills.
In this Interview tutorial, by practicing C Programs MCQ, you can build a solid foundation in one of the most widely used programming languages. To further enhance your skills, you can enroll in a C programming language online course free and take your learning to the next level!
Top 50+ C Programs Questions and Answers MCQs
Test your skills with Top 50+ C Programs MCQ Questions and Answers—perfect for interviews and exams! Try these C Programs MCQs and see how many you get right!
Q 1: Who developed the C programming language, and when was it developed?
- (a) Dennis Ritchie, 1972
- (b) Bjarne Stroustrup, 1985
- (c) Ken Thompson, 1970
- (d) James Gosling, 1995
Q 2: Which of the following is the correct syntax to print "Hello, World!" in C?
- (a) printf("Hello, World!");
- (b) echo("Hello, World!");
- (c) print("Hello, World!");
- (d) System.out.println("Hello, World!");
Q 3: Which operator is used to access a structure member in C?
- (a) . (dot) operator
- (b) -> (arrow) operator
- (c) : (colon) operator
- (d) ; (semicolon) operator
Q 4: What is the correct syntax for a C function that accepts an integer parameter and returns a float?
- (a) float function(int x);
- (b) int function(float x);
- (c) void function(int x);
- (d) float function(float x);
Q 5: What is the purpose of the "break" statement in a C program?
- (a) It terminates the program immediately
- (b) It skips the current iteration in a loop
- (c) It terminates the loop or switch statement
- (d) It does nothing
Q 6: What will be the output of the following C code?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", ++x);
return 0;
}
- (a) 5
- (b) 6
- (c) 4
- (d) Error
Q 7: What is the result of the following code?
#include <stdio.h>
int main() {
int x = 5, y = 3;
printf("%d", x / y);
return 0;
}
- (a) 1
- (b) 2
- (c) 1.666
- (d) Error
Q 8: What is the correct syntax to declare an array in C?
- (a) int arr[];
- (b) int arr[10];
- (c) int arr[10] = {0};
- (d) All of the above
Q 9: What is the output of the following C code?
#include <stdio.h>
int main() {
int x = 10;
printf("%d", x++);
return 0;
}
- (a) 9
- (b) 10
- (c) 11
- (d) None of the above
Q 10: Which of the following is the correct way to define a constant variable in C?
- (a) const int x = 10;
- (b) #define x 10
- (c) Both (a) and (b)
- (d) None of the above
Q 11: What is the correct syntax to define a pointer to an integer in C?
- (a) int *ptr;
- (b) int ptr*;
- (c) *int ptr;
- (d) int ptr;
Q 12: What will be the output of the following C code?
#include <stdio.h>
int main() {
char str[] = "C Programming";
printf("%c", str[3]);
return 0;
}
- (a) C
- (b) P
- (c) G
- (d) r
Q 13: What is the output of the following C code?
#include <stdio.h>
int main() {
int a = 5, b = 10;
if (a > b)
printf("A is greater");
else
printf("B is greater");
return 0;
}
- (a) A is greater
- (b) B is greater
- (c) No output
- (d) Error
Q 14: What is the output of the following C code?
#include <stdio.h>
int main() {
char c = 'A';
printf("%c", c + 1);
return 0;
}
- (a) B
- (b) C
- (c) A
- (d) Error
Q 15: Which of the following is used to terminate a function in C?
- (a) stop
- (b) break
- (c) return
- (d) exit
Q 16: What is the output of the following C code?
#include <stdio.h>
int main() {
int x = 10, y = 5;
printf("%d", x % y);
return 0;
}
- (a) 10
- (b) 5
- (c) 0
- (d) 2
Q 17: Which of the following is correct about the function "strlen()" in C?
- (a) It returns the size of the string
- (b) It returns the number of characters in the string
- (c) It returns the length of the string including the null terminator
- (d) None of the above
Q 18: What is the correct way to declare a function that does not return any value in C?
- (a) void functionName();
- (b) functionName(void);
- (c) int functionName(void);
- (d) None of the above
Q 19: What is the output of the following C code?
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4};
printf("%d", arr[3]);
return 0;
}
- (a) 1
- (b) 2
- (c) 4
- (d) Error
Q 20: How do you define a function that takes a pointer as an argument in C?
- (a) void function(int *ptr);
- (b) void function(int ptr);
- (c) void function(int &ptr);
- (d) None of the above
Q 21: What will be the output of the following C code?
#include <stdio.h>
int main() {
int i = 5;
printf("%d", i++);
return 0;
}
- (a) 5
- (b) 6
- (c) Error
- (d) Undefined behavior
Q 22: Which of the following is true about a function in C?
- (a) A function can only return one value
- (b) A function can return multiple values
- (c) A function cannot return any value
- (d) A function can return any number of values
Q 23: What is the correct way to define an array of 10 integers in C?
- (a) int arr[10];
- (b) int arr(10);
- (c) int arr{10};
- (d) int arr[] = {10};
Q 24: What is the output of the following C code?
#include <stdio.h>
int main() {
int x = 5;
int y = 10;
printf("%d", ++x + y);
return 0;
}
- (a) 15
- (b) 16
- (c) 14
- (d) 10
Q 25: Which of the following is the correct syntax for defining a structure in C?
- (a) struct { int a; int b; };
- (b) structure { int a; int b; };
- (c) struct struct_name { int a; int b; };
- (d) struct_name { int a; int b; };
Q 26: What does the following C code print?
#include <stdio.h>
int main() {
printf("%d", 10 + 20 * 30 / 15);
return 0;
}
- (a) 100
- (b) 80
- (c) 90
- (d) 120
Q 27: What is the size of an int in C?
- (a) 2 bytes
- (b) 4 bytes
- (c) 8 bytes
- (d) Depends on the system
Q 28: What is the output of the following C program?
#include <stdio.h>
int main() {
int a = 5, b = 10;
if (a > b)
printf("a is greater");
else
printf("b is greater");
return 0;
}
- (a) a is greater
- (b) b is greater
- (c) Syntax error
- (d) Logical error
Q 29: Which of the following is used to define a constant in C?
- (a) const
- (b) #define
- (c) Both a and b
- (d) None of the above
Q 30: What is the correct way to declare a pointer to an integer in C?
- (a) int *ptr;
- (b) int &ptr;
- (c) pointer int ptr;
- (d) int ptr*;
Q 31: Which of the following is correct to access a member of a structure through a pointer?
- (a) ptr.member
- (b) ptr->member
- (c) ptr.member->
- (d) &ptr->member
Q 32: Which of the following is the correct way to define a string in C?
- (a) char str = "Hello";
- (b) char str[] = "Hello";
- (c) string str = "Hello";
- (d) char str = 'Hello';
Q 33: What is the output of the following code?
#include <stdio.h>
int main() {
int a = 10, b = 20;
printf("%d", a + b);
return 0;
}
- (a) 30
- (b) 1020
- (c) Syntax error
- (d) None of the above
Q 34: Which of the following is used to declare a constant pointer in C?
- (a) const int *ptr;
- (b) int const *ptr;
- (c) int *const ptr;
- (d) Both b and c
Q 35: What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 10;
printf("%d", ++x);
return 0;
}
- (a) 9
- (b) 10
- (c) 11
- (d) Compilation error
Q 36: 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 < 10, i++
- (c) for (int i <= 10; i++)
- (d) for (int i = 0; i++ < 10)
Q 37: Which function is used to read a string in C?
- (a) scanf()
- (b) gets()
- (c) fgets()
- (d) All of the above
Q 38: Which of the following statements is correct about the malloc() function in C?
- (a) It allocates memory at runtime
- (b) It initializes the memory to 0
- (c) It frees memory that was allocated earlier
- (d) None of the above
Q 39: What is the output of the following code?
#include <stdio.h>
int main() {
char str[] = "C programming";
printf("%s", str);
return 0;
}
- (a) C programming
- (b) C programmingC programming
- (c) Syntax error
- (d) None of the above
Q 40: What is the output of the following code?
#include
int main() {
int x = 10, y = 5;
printf("%d", x / y);
return 0;
}
- (a) 2
- (b) 2.0
- (c) 10
- (d) Compilation error
Q 41: What will the following program output?
#include
int main() {
char str[20];
gets(str);
printf("%s", str);
return 0;
}
- (a) The input string
- (b) Error due to buffer overflow
- (c) Compilation error
- (d) Undefined behavior
Q 42: Which of the following is true about the `sizeof` operator in C?
- (a) It returns the size of the operand in bytes
- (b) It is a compile-time operator
- (c) It works for any data type, including arrays
- (d) All of the above
Q 43: Which of the following is the correct syntax to declare a pointer in C?
- (a) int ptr;
- (b) int *ptr;
- (c) int &ptr;
- (d) None of the above
Q 44: What is the purpose of the `break` statement in C?
- (a) To exit a loop or switch statement
- (b) To continue the current iteration of a loop
- (c) To exit the program
- (d) None of the above
Q 45: What is the correct way to define a structure in C?
- (a) struct {int x; float y;} myStruct;
- (b) struct myStruct {int x; float y;};
- (c) struct myStruct {int x, float y;};
- (d) None of the above
Q 46: What is the output of the following code?
#include <stdio.h>
int main() {
int x = 3, y = 4;
printf("%d", ++x * y);
return 0;
}
- (a) 12
- (b) 15
- (c) 7
- (d) 11
Q 47: What does the following C function do?
#include <stdio.h>
void func(int *a, int *b) {
*a = *a + *b;
}
int main() {
int x = 5, y = 10;
func(&x, &y);
printf("%d", x);
return 0;
}
- (a) 15
- (b) 10
- (c) 5
- (d) 0
Q 48: What is the purpose of the `return` statement in a C function?
- (a) To return a value from the function to the caller
- (b) To exit the function and return to the calling function
- (c) Both (a) and (b)
- (d) None of the above
Q 49: Which of the following is the correct syntax for a while loop in C?
- (a) while (condition) { ... }
- (b) while condition { ... }
- (c) for (condition) { ... }
- (d) loop (condition) { ... }
Q 50: How can you dynamically allocate memory for an array of 10 integers in C?
- (a) int *arr = malloc(10 * sizeof(int));
- (b) int arr[10];
- (c) int *arr = malloc(sizeof(int[10]));
- (d) Both (a) and (c)
Q 52: What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 5, b = 0;
printf("%d", a && b);
return 0;
}
- (a) 0
- (b) 1
- (c) -1
- (d) Compilation error
Q 53: What is the output of this code snippet?
#include <stdio.h>
#define SQUARE(x) x * x
int main() {
printf("%d", SQUARE(3 + 1));
return 0;
}
- (a) 16
- (b) 12
- (c) Compilation error
- (d) None of the above
Q 54: What is the default value of a global variable in C?
- (a) Undefined
- (b) Zero
- (c) Garbage value
- (d) Null
Q 55: Which keyword is used to prevent a variable from being modified?
- (a) const
- (b) volatile
- (c) static
- (d) extern
Q 56: Which loop in C executes the code block at least once, regardless of the condition?
- (a) for Loop
- (b) while Loop
- (c) do...while Loop
- (d) None of the above
Q 57: What is the purpose of the "if...else statement in C"?
- (a) To execute code unconditionally
- (b) To check multiple conditions
- (c) To choose between two blocks of code based on a condition
- (d) None of the above
Q 58: What will be the output of the following code?
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr;
ptr = (int *)malloc(2 * sizeof(int));
ptr[0] = 10;
ptr[1] = 20;
ptr = realloc(ptr, 3 * sizeof(int));
ptr[2] = 30;
printf("%d %d %d", ptr[0], ptr[1], ptr[2]);
free(ptr);
return 0;
}
- (a) 10 20 0
- (b) 10 20 30
- (c) Undefined behavior
- (d) Compilation error
Q 59: What is the purpose of the "for Loop in C"?
- (a) To iterate a block of code a fixed number of times
- (b) To create infinite loops only
- (c) To make decisions
- (d) To perform file operations
Q 60: Which operator is used to assign a value to a variable in C?
- (a) ==
- (b) =
- (c) :=
- (d) equals
Q 61: What are reserved words in C that cannot be used as identifiers?
- (a) Literals
- (b) Keywords
- (c) Variables
- (d) Functions
Q 62: What is the output of the following C program?
#include <stdio.h>
int main() {
int i = 0;
while (i < 5) {
printf("%d ", i);
i++;
}
return 0;
}
- (a) 0 1 2 3 4
- (b) 1 2 3 4 5
- (c) 0 1 2 3 4 5
- (d) Compilation error
Q 63: In C, which function dynamically allocates memory for an array?
- (a) malloc()
- (b) calloc()
- (c) realloc()
- (d) free()
Q 64: Which data structure uses LIFO (Last In, First Out) order?
- (a) Queue
- (b) Stack
- (c) Linked List
- (d) Tree
Q 65: Which data structure is best suited for implementing recursion?
- (a) Stack
- (b) Queue
- (c) Array
- (d) Linked List
Q 66: What is the time complexity of searching an element in an unsorted array?
- (a) O(1)
- (b) O(n)
- (c) O(log n)
- (d) O(n log n)
Q 67: What is the worst-case time complexity of QuickSort?
- (a) O(n log n)
- (b) O(n)
- (c) O(n²)
- (d) O(log n)
Q 68: Which data structure is used for implementing a priority queue?
- (a) Stack
- (b) Queue
- (c) Heap
- (d) Linked List
Q 69: Which sorting algorithm is the most efficient for large datasets?
- (a) Bubble Sort
- (b) Selection Sort
- (c) Merge Sort
- (d) Insertion Sort
Q 70: Which data structure is used to convert infix expressions to postfix notation?
- (a) Queue
- (b) Stack
- (c) Heap
- (d) Graph
Q 71: Which of the following data structures is used in Breadth-First Search (BFS)?
- (a) Stack
- (b) Queue
- (c) Heap
- (d) Linked List
Q 72: What is the space complexity of an adjacency matrix for a graph with N nodes?
- (a) O(N)
- (b) O(N²)
- (c) O(log N)
- (d) O(N log N)
Q 73: What is the worst-case time complexity of searching in a balanced binary search tree (BST)?
- (a) O(1)
- (b) O(n)
- (c) O(log n)
- (d) O(n log n)
Q 74: Which traversal method processes the left subtree, root, and then the right subtree?
- (a) Preorder
- (b) Inorder
- (c) Postorder
- (d) Level-order
Q 75: Which data structure is used to detect cycles in a graph?
- (a) Stack
- (b) Queue
- (c) Union-Find
- (d) Heap
Conclusion
In conclusion, C Programs MCQ helps in understanding fundamental concepts of C programming with real-world examples. Practicing C Programs MCQ improves problem-solving skills and prepares you for exams and interviews. With these C Programs MCQ, you can test your knowledge and strengthen your coding basics efficiently. Overall, they are a valuable tool for mastering C programming.
Dear learners, join our Tech Trendy Masterclasses to help you learn and immerse yourself in the latest trending technologies and upgrade your tech skills with the latest skills trends, design, and practices.