0% found this document useful (0 votes)
5 views

C MCQ

IMPORTANT MCQ

Uploaded by

Raja Daniyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

C MCQ

IMPORTANT MCQ

Uploaded by

Raja Daniyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Basics of C

 Sample MCQ: What is the correct file extension for a C program?


o A) .cpp
o B) .c
o C) .cs
o D) .exe
Answer: B) .c

2. Data Types

 Sample MCQ: Which of the following is a correct datatype in C?


o A) int
o B) boolean
o C) string
o D) char[]
Answer: A) int

3. Variables

 Sample MCQ: How do you declare a variable in C?


o A) int x;
o B) var int x;
o C) define int x;
o D) let x;
Answer: A) int x;

4. Operators

 Sample MCQ: What is the output of the expression 5 % 2 in C?


o A) 0
o B) 1
o C) 2
o D) 5
Answer: B) 1
5. Control Statements

 Sample MCQ: Which of the following is a valid if statement in C?


o A) if x = 10
o B) if (x == 10)
o C) if (x = 10)
o D) if x == 10
Answer: B) if (x == 10)

6. Loops

 Sample MCQ: Which loop will always execute at least once in C?


o A) for
o B) while
o C) do-while
o D) for-while
Answer: C) do-while

7. Functions

 Sample MCQ: How do you declare a function in C that returns an integer?


o A) function int myFunction()
o B) int myFunction()
o C) int = myFunction()
o D) def int myFunction()
Answer: B) int myFunction()

8. Arrays

 Sample MCQ: How do you declare an array of integers in C?


o A) int arr[] = {1, 2, 3};
o B) arr int[] = {1, 2, 3};
o C) int arr = {1, 2, 3};
o D) int[] arr = {1, 2, 3};
Answer: A) int arr[] = {1, 2, 3};
9. Pointers

 Sample MCQ: Which of the following correctly declares a pointer in C?


o A) int *ptr;
o B) pointer int ptr;
o C) ptr = int *;
o D) int ptr*;
Answer: A) int *ptr;

10. Memory Allocation

 Sample MCQ: What function is used to dynamically allocate memory in C?


o A) malloc()
o B) alloc()
o C) calloc()
o D) new()
Answer: A) malloc()

11. Strings

 Sample MCQ: Which of the following is correct to declare a string in C?


o A) char str[] = "Hello";
o B) string str = "Hello";
o C) char[] str = {"H", "e", "l", "l", "o"};
o D) char str[5] = "Hello";
Answer: A) char str[] = "Hello";

12. Structures

 Sample MCQ: How do you declare a structure in C?


o A) structure myStruct { int x; }
o B) struct myStruct { int x; }
o C) myStruct struct { int x; }
o D) structure: myStruct { int x; }
Answer: B) struct myStruct { int x; }
13. File Handling

 Sample MCQ: Which function is used to open a file in C?


o A) open()
o B) fopen()
o C) read()
o D) fileopen()
Answer: B) fopen()

14. Preprocessor Directives

 Sample MCQ: What does #include<stdio.h> do in a C program?


o A) Includes the Standard Input Output header file.
o B) Includes the String header file.
o C) Declares main function.
o D) Declares standard variables.
Answer: A) Includes the Standard Input Output header file.

15. Macros

 Sample MCQ: Which preprocessor directive is used to define a macro in C?


o A) #macro
o B) #define
o C) #include
o D) #ifdef
Answer: B) #define

16. Recursion

 Sample MCQ: A function in C that calls itself is known as:


o A) Iterative function
o B) Recursive function
o C) Inherited function
o D) Pointer function
Answer: B) Recursive function

17. Command Line Arguments


 Sample MCQ: Which of the following is used to receive command line arguments
in C?
o A) int main(int argc, char *argv[])
o B) void main(int argc, char *argv[])
o C) int main(int arg)[]
o D) int argv(int argc)
Answer: A) int main(int argc, char *argv[])

18. Storage Classes

 Sample MCQ: Which of the following is not a storage class in C?


o A) auto
o B) register
o C) private
o D) static
Answer: C) private

19. Bitwise Operators

 Sample MCQ: Which of the following is a bitwise AND operator in C?


o A) &&
o B) &
o C) ||
o D) |
Answer: B) &

20. Dynamic Memory Allocation

 Sample MCQ: Which function is used to allocate memory for an array in C?


o A) malloc()
o B) calloc()
o C) alloc()
o D) array()
Answer: B) calloc()

21. Typecasting
 Sample MCQ: How do you cast an integer i to a float in C?
o A) (float)i
o B) float(i)
o C) (float) i
o D) i.toFloat()
Answer: C) (float) i

22. Linked Lists

 Sample MCQ: What is a linked list in C?


o A) A data structure where elements are stored at contiguous memory
locations.
o B) A data structure where elements are linked using pointers.
o C) A variable that can store multiple values of the same type.
o D) A type of array.
Answer: B) A data structure where elements are linked using pointers.

23. Enumerations

 Sample MCQ: How do you declare an enum in C?


o A) enum Color { Red, Green, Blue };
o B) enumeration Color { Red, Green, Blue };
o C) enum Colors[] = { Red, Green, Blue };
o D) enum Colors = { Red, Green, Blue };
Answer: A) enum Color { Red, Green, Blue };

24. Multithreading

 Sample MCQ: How do you create a new thread in C?


o A) Using pthread_create()
o B) Using thread_start()
o C) Using new_thread()
o D) Using thread()
Answer: A) Using pthread_create()

25. Garbage Collection


 Sample MCQ: Which of the following is true regarding garbage collection in C?
o A) C has automatic garbage collection.
o B

You might also like