C Programs MCQ:  For Beginners and Experts

C Programs MCQ: For Beginners and Experts

31 Dec 2024
Question
66 Views
60 min read
Learn with an interactive course and practical hands-on labs

C Programming Free Course with Certificate: Learn C In 21 Days

C Programs MCQ

C Programs MCQ is a collection of multiple-choice questions aimed at testing your proficiency in the C programming language. These questions cover key topics such as variables in C, loops in C, arrays in C, functions in C, and pointers in C, helping learners strengthen their fundamentals. Whether you're preparing for exams, interviews, or competitive tests, C Programs MCQ provides an excellent way to assess and improve your knowledge.

In this Interview tutorial, by practicing C Programs MCQ, you can build a solid foundation in one of the most widely used programming languages.

Top 50+ C Programs Questions and Answers MCQs

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 a 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()
Conclusion

In conclusion, C programs MCQ are an excellent resource for testing and enhancing your understanding of the C programming language. These questions cover fundamental to advanced concepts, helping learners prepare for interviews and exams effectively. Practicing C programs MCQ improves problem-solving skills and familiarity with key programming techniques. 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.

Further Read:
Top 50+ Wipro Interview Questions & Answers for Freshers & Experienced (2025)
Top Google Interview Questions & Answers for Freshers (2025)
Top-Picked 60+ Accenture Interview Q&A for Freshers & Experienced 2025

FAQs

The main() function is the entry point of any C program. It is where program execution begins and ends. 

C provides functions like malloc(), calloc(), and realloc() for dynamic memory allocation, while free() is used to release the allocated memory. 

Header files in C, such as <stdio.h> or <stdlib.h>, contain function declarations, macros, and definitions used by the program. 

A pointer is a variable that stores the memory address of another variable. Pointers are essential for dynamic memory allocation, arrays, and accessing hardware. 

Local variables are declared within a function and are accessible only within that function. Global variables are declared outside all functions and can be accessed by any function in the program. 

Recursion is a programming technique where a function calls itself directly or indirectly to solve a problem, typically breaking it into smaller sub-problems. 
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.

Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.
Accept cookies & close this