C Programming MCQ PDF
1. What is the disadvantage of arrays in C?
A. Multiple other data structures can be implemented using arrays
B. the amount of memory to be allocated needs to be known beforehand.
C. Elements of array can be accessed in constant time
D. Elements are stored in contiguous memory blocks
Answer: the amount of memory to be allocated needs to be known beforehand.
2. How many bytes does "int = D" use?
A. 1
B. 0
C. 10
D. 2 or 4
Answer: 2 or 4
3. Directives are translated by the__________
A. Pre-processor
B. Compiler
C. Linker
D. Editor
Answer: Pre-processor
4. What feature makes C++ so powerful?
A. Reusing the old code
B. Easy implementation
C. Easy memory management
D. All of the above
Answer: All of the above
5. What is the maximum number of characters that can be held in the string variable
char address line [40]?
A. 39
B. 41
C. 40
D. 38
Answer: 39
6. Which of the following SLT template class is a container adaptor class?
A. Deque
B. Vector
C. List
D. Stack
Answer: Stack
7. If addition had higher precedence than multiplication, then the value of the
expression (1 + 2 * 3 + 4 * 5) would be which of the following?
A. 27
B. 105
C. 69
D. 47
Answer: 105
Explanation: (1 + 2 * 3 + 4 * 5)
= (1 + 2) * (3 + 4) * 5
=3*7*5
= 105
8. Each instance of a class has a different set of______
A. Attribute values
B. Class interfaces
C. Return types
D. Methods
Answer: Attribute values
9. What is the return type of the fopen() function in C?
A. An integer
B. pointer to a FILE object
C. Pointer to an integer
D. None of the above
Answer: pointer to a FILE object
10. How to find the length of an array in C?
A. sizeof(a)/sizeof(a[0])
B. sizeof(a)
C. sizeof(a)*sizeof(a[0])
D. None of the above
Answer: sizeof(a)/sizeof(a[0])
11. Which of the following is not a storage class specifier in C?
A. extern
B. volatile
C. typedef
D. static
Answer: volatile
12. Which of the following will occur if we call the free() function on a NULL pointer?
A. The program will execute normally
B. Compilation Error
C. Runtime error
D. undefined behavior
Answer: The program will execute normally
13. Which of the following should be used to free memory from a pointer allocated
using the “new” operator?
A. free()
B. realloc()
C. delete
D. None of the above
Answer: delete
14. Which data structure is used to handle recursion in C?
A. Stack
B. Queue
C. Trees
D. Deque
Answer: Stack
15. Which of the following is not true about structs in C?
A. Functions are allowed inside structs
B. Constructors are not allowed inside structs
C. No data hiding
D. Cannot have static members in struct body
Answer: Functions are allowed inside structs
16. How is the 3rd element in an array accessed based on pointer notation?
A. *a + 3
B. *(*a+3)
C. *(a + 3)
D. & (a+3)
Answer: *(a + 3)
17. Which of the following function is used to open a file in C++?
A. fgets
B. fseek
C. fclose
D. fopen
Answer: fopen ()
18. Which of the following are correct file opening modes in C?
A. w
B. r
C. rb
D. All of the above
Answer: All of the above
19. What is required in each C program?
A. The program does not require any function.
B. The program must have at least one function
C. Output data
D. Input data
Answer: The program must have at least one function
20. In which of the following languages is function overloading not possible?
A. C++
B. C
C. Python
D. Java
Answer: C
21. What is the output of this statement "printf("%d", (a++))"?
A. Error message
B. The value of (a + 1)
C. The current value of a
D. Garbage
Answer: The current value of a
22. Why is a macro used in place of a function?
A. It reduces code size
B. It reduces execution time
C. It increases code size
D. It increases execution time
Answer: It reduces code size
23. What is the 16-bit compiler allowable range for integer constants?
A. -3.4e38 to 3.4e38
B. -32767 to 32768
C. -32668 to 32667
D. -32768 to 32767
Answer: -32768 to 32767
24. What is a lint?
A. Interactive debugger
B. C compiler
C. C interpreter
D. Analyzing tool
Answer: Analyzing tool
25. If p is an integer pointer with a value 1000, then what will the value of p + 5 be?
A. 1005
B. 1020
C. 1004
D. 1010
Answer: 1020
26. How to declare a double-pointer in C?
A. int **val
B. int *val
C. int **val
D. int &val
Answer: int **val
27. What is the size of the int data type (in bytes) in C?
A. 4
B. 8
C. 2
D. 1
Answer: 4
28. In the C language, the constant is defined _______.
A. Before main
B. Anywhere, but starting on a new line.
C. After main
D. None of the these
Answer: Anywhere, but starting on a new line
29. How are String represented in memory in C?
A. An Array of characters
B. Linked list of characters
C. The object of some class
D. Some as other primitive data types
Answer: An Array of characters
30. Which of the following is an exit controlled loop?
A. While loop
B. For loop
C. do-while loop
D. None of the above
Answer: do-while loop