Skip to content

Instantly share code, notes, and snippets.

@024x
Last active August 15, 2023 03:28
Show Gist options
  • Select an option

  • Save 024x/f0cd8ba6800e1b1cda2b7bd3fbde5149 to your computer and use it in GitHub Desktop.

Select an option

Save 024x/f0cd8ba6800e1b1cda2b7bd3fbde5149 to your computer and use it in GitHub Desktop.
MCQ's to Test Understandings in C - A gist that contains multiple choice questions to test your understanding of various topics in C language. - Satyendra

MCQ's to Test Understandings in C


  1. What is C?
    • A) A high-level programming language
    • B) A low-level programming language
    • C) A scripting language
    • D) A markup language

  1. What is the purpose of a header file in C?
    • A) To declare functions and variables
    • B) To define functions and variables
    • C) To declare and define functions and variables
    • D) None of the above

  1. Which of the following is not a basic data type in C?
    • A) int
    • B) float
    • C) double
    • D) string

  1. What is the syntax for declaring an integer variable in C?
    • A) var x = 5;
    • B) int x = 5;
    • C) x = 5;
    • D) integer x = 5;

  1. What is the output of the following code?
    #include <stdio.h>
    
    int main() {
        printf("%d", sizeof(char));
        return 0;
    }
    • A) 1
    • B) 2
    • C) 4
    • D) 8

  1. What is the purpose of the if statement in C?
    • A) To loop through a block of code
    • B) To execute a block of code if a condition is true
    • C) To execute a block of code if a condition is false
    • D) To define a function

  1. What is a function in C?
    • A) A block of code that performs a specific task
    • B) A variable that stores a value
    • C) A type of loop
    • D) A conditional statement

  1. What is the purpose of the return statement in C?
    • A) To terminate the program
    • B) To exit a loop
    • C) To return a value from a function
    • D) None of the above

  1. What is the syntax for a for loop in C?
    • A) for (int i = 0; i < 10; i++)
    • B) for (i = 0; i < 10; i++)
    • C) for i = 0 to 10
    • D) for (int i = 0; i < 10)

  1. What is the purpose of the break statement in C?
    • A) To exit a loop
    • B) To skip to the next iteration of a loop
    • C) To return a value from a function
    • D) None of the above

  1. What is the purpose of the continue statement in C?
    • A) To exit a loop
    • B) To skip to the next iteration of a loop
    • C) To return a value from a function
    • D) None of the above

  1. What is the purpose of the switch statement in C?
    • A) To define a function
    • B) To loop through a block of code
    • C) To execute a block of code based on the value of an expression
    • D) None of the above

  1. What is the syntax for a do-while loop in C?
    • A) do (i = 0; i < 10; i++)
    • B) do while (i < 10)
    • C) while (i < 10) do
    • D) do { /* code */ } while (i < 10)

  1. What is the purpose of the typedef keyword in C?
    • A) To define a new data type
    • B) To declare a variable
    • C) To define a function
    • D) None of the above

  1. What is a pointer in C?
    • A) A variable that stores the address of another variable
    • B) A type of loop
    • C) A conditional statement
    • D) None of the above

  1. What is the purpose of the malloc() function in C?
    • A) To allocate memory dynamically
    • B) To free allocated memory
    • C) To copy a string
    • D) None of the above

  1. What is the purpose of the fgets() function in C?
    • A) To read a line of text from a file
    • B) To write a line of text to a file
    • C) To copy a string
    • D) None of the above

  1. What is the purpose of the fopen() function in C?
    • A) To open a file for reading
    • B) To open a file for writing
    • C) To open a file for both reading and writing
    • D) All of the above

  1. What is the purpose of the fclose() function in C?
    • A) To close a file
    • B) To open a file
    • C) To read data from a file
    • D) None of the above

  1. What is the purpose of the feof() function in C?
    • A) To check if the end of a file has been reached
    • B) To check if a file exists
    • C) To check if a file is open
    • D) None of the above


Answers:
1. A
2. A
3. D
4. B
5. A
6. B
7. A
8. C
9. A
10. A
11. B
12. C
13. D
14. A
15. A
16. A
17. A
18. D
19. A
20. A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment