1. What is an array?
a) A data structure that stores elements of the same type sequentially in memory
b) A data structure that stores elements of different types randomly in memory
c) A data structure that stores elements of the same type randomly in memory
d) A data structure that organizes elements in a tree-like hierarchy
Answer: a) A data structure that stores elements of the same type sequentially in memory
Explanation: An array is a collection of elements of the same type that are stored sequentially in memory. Each element is accessed by its index or position in the array.
2. How is a 1D array initialized?
a) By assigning values to each element separately
b) By specifying the size and initializing values using curly braces {}
c) By specifying the size and using a loop to assign values
d) By specifying the size and initializing values using parentheses ()
Answer: b) By specifying the size and initializing values using curly braces {}
Explanation: When initializing a 1D array, you specify the size of the array and provide the initial values within curly braces {}.
3. What is bound checking in arrays?
a) Ensuring that the array is properly bounded within memory limits
b) Checking if an index is within the valid range for array access
c) Verifying the data type of elements in the array
d) Counting the total number of elements in the array
Answer: b) Checking if an index is within the valid range for array access
Explanation: Bound checking involves verifying that the index used to access an array element is within the valid range of indices for that array.
4. How is a 2D array initialized?
a) By specifying the size of both dimensions and providing initial values
b) By specifying the size of one dimension and providing initial values for the other
c) By using a loop to assign values to each element
d) By specifying the size of both dimensions without providing initial values
Answer: a) By specifying the size of both dimensions and providing initial values
Explanation: A 2D array is initialized by specifying the size of both dimensions and providing initial values within nested curly braces {}.
5. What is the memory map of a 1D array?
a) It is a diagram showing the physical layout of elements in memory
b) It is a graphical representation of array indices
c) It is a table listing the size and data type of elements in the array
d) It is a representation of array elements in a tree structure
Answer: a) It is a diagram showing the physical layout of elements in memory
Explanation: The memory map of a 1D array depicts how elements are sequentially stored in memory, indicating their addresses and order.
6. What is a multidimensional array?
a) An array that can hold elements of different data types
b) An array with more than one dimension
c) An array that dynamically adjusts its size
d) An array that can only store integers
Answer: b) An array with more than one dimension
Explanation: A multidimensional array is an array with two or more dimensions, allowing elements to be arranged in rows and columns or higher-dimensional structures.
7. What are strings in programming?
a) A collection of characters treated as a single data entity
b) A data structure used for storing integers
c) A type of array that can only store characters
d) A data structure used for mathematical computations
Answer: a) A collection of characters treated as a single data entity
Explanation: In programming, a string is a sequence of characters, typically used to represent text or words.
8. Which function is used to find the length of a string in C?
a) strlen()
b) strlength()
c) length()
d) size()
Answer: a) strlen()
Explanation: The strlen() function is used to find the length of a string in C, returning the number of characters in the string excluding the null terminator.
9. What does the strcpy() function do?
a) Compares two strings
b) Concatenates two strings
c) Copies one string to another
d) Searches for a substring within a string
Answer: c) Copies one string to another
Explanation: The strcpy() function in C is used to copy the contents of one string to another string.
10. What is the purpose of strcmp() function?
a) Concatenates two strings
b) Copies one string to another
c) Compares two strings lexicographically
d) Finds the length of a string
Answer: c) Compares two strings lexicographically
Explanation: The strcmp() function compares two strings lexicographically, returning an integer value indicating their relationship (greater than, less than, or equal).