50 Multiple Choice Questions: Programming II Concepts
1. What is an array?
A) A variable that stores multiple values of the same type
B) A function that returns multiple values
C) A data type that stores different types
D) A single variable with one value
2. How do you declare a single-dimensional array in C++?
A) int array[];
B) array int[10];
C) int array[10];
D) int (10) array;
3. In array declaration, what does the "size" specify?
A) Data type
B) Name of array
C) Number of elements
D) Memory address
4. What is the purpose of an array index?
A) To store data type
B) To access individual elements
C) To name the array
D) To declare the array
5. How can you declare an array with empty members?
A) int arr[] = {};
B) int arr[0];
C) int arr[];
D) int arr = [];
6. What is a string in programming?
A) A sequence of integers
B) A sequence of characters
C) A single character
D) A boolean value
7. What is a C-string?
A) A string class in C++
B) A null-terminated character array
C) A dynamic string
D) A string with no end
8. How is a C++ string declared?
A) string s = "Hello";
B) char s = "Hello";
C) s = "Hello";
D) string s('Hello');
9. Which function is used to read a string with spaces in C++?
A) cin
B) getline()
C) scanf()
D) read()
10. What is a structure (struct) in C++?
A) A function
B) A user-defined data type grouping variables
C) A loop
D) A pointer type
11. Which of the following is a characteristic of a struct?
A) Can only store one data type
B) Members are private by default in C++
C) Can store different data types
D) Cannot be passed to functions
12. How do you initialize data in a struct?
A) Using :: operator
B) Using . dot operator
C) Using -> arrow operator
D) Using & operator
13. How do you access struct members?
A) [Link]
B) member->struct
C) struct::member
D) [Link]
14. Which header file is needed for strcpy()?
A) <iostream>
B) <cstring>
C) <string>
D) <vector>
15. What is recursion?
A) A loop structure
B) A function calling another function
C) A function calling itself
D) A data structure
16. What is a base case in recursion?
A) The recursive call
B) The condition that stops recursion
C) The main function
D) The return type
17. Where is recursion commonly used?
A) Sorting algorithms
B) File handling
C) Variable declaration
D) Arithmetic operations
18. What is an advantage of recursion?
A) Always faster than iteration
B) More memory efficient
C) Simplifies code for certain problems
D) No stack overhead
19. What is a disadvantage of recursion?
A) Can cause stack overflow
B) Always slower
C) Hard to debug
D) Both A and C
20. What is a pointer?
A) A variable that stores a value
B) A variable that stores a memory address
C) A constant value
D) A function
21. How do you declare a pointer?
A) int ptr;
B) int *ptr;
C) ptr int;
D) *int ptr;
22. How do you get the address of a variable?
A) &var
B) var
C) var&
D) var
23. What is dereferencing?
A) Getting the address of a pointer
B) Getting the value at a memory address
C) Declaring a pointer
D) Deleting a pointer
24. Which operator is used for dereferencing?
A) &
B) *
C)->
D) .
25. Which header file is used for file handling in C++?
A) <cstring>
B) <fstream>
C) <iostream>
D) <filestream>
26. Which class is used for writing to a file?
A) ifstream
B) ofstream
C) fstream
D) iostream
27. What does dynamic memory allocation mean?
A) Memory allocated at compile time
B) Memory allocated at runtime
C) Memory in CPU cache
D) Static memory
28. Which keyword allocates memory dynamically in C++?
A) malloc
B) new
C) alloc
D) create
29. Which keyword deallocates memory in C++?
A) free
B) delete
C) remove
D) dealloc
30. What is an advantage of dynamic memory allocation?
A) Faster access
B) Memory size fixed at compile time
C) Efficient memory usage
D) No memory leaks
31. What is a multidimensional array?
A) An array of arrays
B) A single-dimensional array
C) An array of pointers
D) A dynamic array
32. How do you declare a 2D array?
A) int arr[][];
B) int arr[5][5];
C) array[5,5] int;
D) int arr(5)(5);
33. What is the index range of an array of size n?
A) 0 to n
B) 1 to n
C) 0 to n-1
D) 1 to n-1
34. How do you initialize an array at declaration?
A) int arr = {1,2,3};
B) int arr[3] = {1,2,3};
C) arr[3] = {1,2,3};
D) int arr[] = (1,2,3);
35. What is the difference between C-string and C++ string?
A) No difference
B) C-string is a class, C++ string is an array
C) C-string is array, C++ string is a class
D) C-string is dynamic, C++ string is static
36. Which function copies one C-string to another?
A) strcopy()
B) strcpy()
C) copy()
D) stringcpy()
37. How is a struct variable declared?
A) struct_name var;
B) var struct_name;
C) struct struct_name var;
D) Both A and C
38. Can a struct contain another struct?
A) No
B) Yes
C) Only in C
D) Only with pointers
39. What is the return type of a recursive function?
A) Always void
B) Always int
C) Can be any type
D) Must be pointer
40. What happens if a recursive function lacks a base case?
A) Runs faster
B) Infinite recursion
C) Compilation error
D) Returns zero
41. Which data structure is used internally in recursion?
A) Queue
B) Stack
C) Linked List
D) Array
42. What does a pointer store?
A) Value of variable
B) Data type
C) Memory address
D) Array index
43. What is a null pointer?
A) Pointer to zero
B) Pointer with no address
C) Pointer pointing to nothing
D) Both B and C
44. How do you allocate an array dynamically?
A) int* arr = new int[10];
B) int arr = new[10];
C) int* arr = new int(10);
D) arr = new int[10];
45. How do you deallocate a dynamic array?
A) delete arr;
B) delete[] arr;
C) free(arr);
D) remove arr;
46. Which mode opens a file for writing?
A) ios::in
B) ios::out
C) ios::app
D) ios::binary
47. What is the purpose of ios::app?
A) Read from file
B) Write from beginning
C) Append to file
D) Binary mode
48. What is memory leak?
A) Forgetting to allocate memory
B) Not deallocating dynamic memory
C) Using too much stack memory
D) Static allocation
49. Which is faster: stack or heap memory allocation?
A) Stack
B) Heap
C) Same speed
D) Depends on compiler
50. What is the purpose of the '&' operator with pointers?
A) Dereference
B) Address of
C) Allocate
D) Deallocate
Answer Key:
1-A, 2-C, 3-C, 4-B, 5-A, 6-B, 7-B, 8-A, 9-B, 10-B,
11-C, 12-B, 13-A, 14-B, 15-C, 16-B, 17-A, 18-C, 19-D, 20-B,
21-B, 22-A, 23-B, 24-B, 25-B, 26-B, 27-B, 28-B, 29-B, 30-C,
31-A, 32-B, 33-C, 34-B, 35-C, 36-B, 37-D, 38-B, 39-C, 40-B,
41-B, 42-C, 43-D, 44-A, 45-B, 46-B, 47-C, 48-B, 49-A, 50-B