MCQs on Arrays and Strings | C Programming

Introduction to Arrays (1D and 2D Arrays)

  1. What is an array in C?
    a) A variable that can hold multiple values of different types
    b) A collection of variables of the same type
    c) A single variable that can hold only one value
    d) A function parameter
  2. Which of the following declares a 1D array of integers with 10 elements?
    a) int arr[10];
    b) int arr[10][10];
    c) int arr{10};
    d) int arr(10);
  3. How are elements stored in an array?
    a) Randomly
    b) Sequentially
    c) At runtime
    d) In a tree structure
  4. What is the index of the first element in an array?
    a) -1
    b) 1
    c) 0
    d) 2
  5. If an array has 5 elements, what is the index of the last element?
    a) 5
    b) 4
    c) 3
    d) 6
  6. What will int arr[5] = {1, 2, 3}; initialize in C?
    a) All elements to 0
    b) The first three elements to 1, 2, and 3; others to 0
    c) All elements to 1
    d) The first element only
  7. Which of the following correctly declares a 2D array of integers?
    a) int arr[10, 10];
    b) int arr[10][10];
    c) int arr{10}{10};
    d) int arr(10)(10);
  8. What is the size of a 2D array int arr[3][4];?
    a) 3
    b) 4
    c) 12
    d) 7
  9. In C, which function is used to determine the number of elements in an array?
    a) sizeof()
    b) strlen()
    c) count()
    d) num()
  10. An array can have elements of:
    a) Different types
    b) The same type only
    c) Strings only
    d) Any type

Array Operations (Traversal, Insertion, Deletion)

  1. Which loop is commonly used to traverse a 1D array?
    a) while
    b) for
    c) do-while
    d) goto
  2. What is the correct syntax to access the third element of an array arr?
    a) arr[2]
    b) arr[3]
    c) arr(2)
    d) arr{3}
  3. What does the insertion of an element in an array require?
    a) Reallocating memory
    b) Shifting elements if necessary
    c) Deleting the array
    d) None of the above
  4. To delete an element from an array, what needs to be done?
    a) Directly remove it
    b) Shift the subsequent elements to the left
    c) Initialize it with -1
    d) Use the delete function
  5. Which operation is most efficient on an array?
    a) Traversal
    b) Insertion
    c) Deletion
    d) Sorting

Multidimensional Arrays

  1. What is the general syntax for a multidimensional array in C?
    a) data_type array_name[size1][size2]...[sizeN];
    b) data_type array_name[size1, size2];
    c) data_type array_name{size1,size2};
    d) data_type array_name(size1)(size2);
  2. How is a 3D array declared in C?
    a) int arr[3][3][3];
    b) int arr[3,3,3];
    c) int arr(3)(3)(3);
    d) int arr{3}{3}{3};
  3. What does arr[1][2][3] refer to in a 3D array?
    a) The first element
    b) The second 2D array, third row, fourth column
    c) The last element
    d) A 2D array
  4. In C, how are multidimensional arrays stored in memory?
    a) Column-major order
    b) Random order
    c) Row-major order
    d) In a stack
  5. What is the total number of elements in an array int arr[2][3][4];?
    a) 24
    b) 20
    c) 12
    d) 30

Character Arrays and Strings

  1. What is a character array used for in C?
    a) Storing numbers
    b) Storing strings
    c) Storing functions
    d) Storing arrays
  2. Which of the following declares a string in C?
    a) char str[10] = "Hello";
    b) char str = "Hello";
    c) char str[10] = 'Hello';
    d) char str = 'Hello';
  3. Which character is automatically added to the end of a string in C?
    a) \n
    b) \0
    c) \r
    d) \t
  4. What is the correct way to declare a string of 20 characters?
    a) char str[20];
    b) char str[20][20];
    c) char str{20};
    d) char str(20);
  5. Which function is used to calculate the length of a string?
    a) strlen()
    b) strcat()
    c) strcpy()
    d) strcmp()

String Operations (strlen, strcpy, strcat, strcmp)

  1. Which function is used to copy one string into another?
    a) strcat()
    b) strcpy()
    c) strcmp()
    d) strlen()
  2. Which function is used to concatenate two strings?
    a) strcat()
    b) strcpy()
    c) strcmp()
    d) strlen()
  3. The function strcmp(str1, str2) returns 0 when:
    a) str1 is greater than str2
    b) str1 is less than str2
    c) str1 is equal to str2
    d) str2 is empty
  4. Which function compares two strings lexicographically?
    a) strcat()
    b) strcpy()
    c) strcmp()
    d) strlen()
  5. What will strlen("Hello") return?
    a) 4
    b) 5
    c) 6
    d) 0

Array of Strings

  1. How is an array of strings declared in C?
    a) char arr[5][10];
    b) int arr[5];
    c) string arr[5];
    d) str arr[5];
  2. In an array of strings char arr[3][10];, what does arr[2] represent?
    a) A single character
    b) The third string in the array
    c) The second string in the array
    d) An integer value
  3. How would you access the first character of the second string in arr[3][10];?
    a) arr[2][0]
    b) arr[0][2]
    c) arr[1][0]
    d) arr[0][1]
  4. Which function can be used with an array of strings to sort them lexicographically?
    a) strsort()
    b) qsort()
    c) arraysort()
    d) sort()
  5. An array of strings in C is essentially a:
    a) 1D array of characters
    b) 2D array of characters
    c) 1D array of integers
    d) 3D array of characters

Introduction to Arrays (1D and 2D Arrays) – Continued

  1. If int arr[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };, what is the value of arr[1][2]?
    a) 4
    b) 5
    c) 6
    d) 9
  2. In C, when using int arr[10];, how many bytes are allocated if int is 4 bytes?
    a) 10
    b) 20
    c) 40
    d) 80
  3. What will happen if you try to access an index outside the array bounds in C?
    a) It will return 0
    b) It will wrap around to the start of the array
    c) Undefined behavior
    d) It will throw an error

Array Operations (Traversal, Insertion, Deletion) – Continued

  1. What is the time complexity of accessing an element in a 1D array?
    a) O(n)
    b) O(n^2)
    c) O(log n)
    d) O(1)
  2. In C, what does arr[5] = arr[4]; do if arr is an integer array?
    a) Copies all elements from arr[4] to arr[5]
    b) Sets arr[5] to the value of arr[4]
    c) Deletes arr[5]
    d) None of the above

Character Arrays and Strings – Continued

  1. Which header file must be included to use string functions like strlen and strcpy?
    a) #include <stdlib.h>
    b) #include <math.h>
    c) #include <string.h>
    d) #include <stdio.h>
  2. If char str[] = "Hello";, what is the value of str[5]?
    a) 'o'
    b) 'H'
    c) \0
    d) undefined
  3. Which of the following statements is correct about strings in C?
    a) Strings are stored as int arrays
    b) Strings are character arrays terminated by \0
    c) Strings cannot be modified
    d) Strings are always 100 characters long
  4. Which function can be used to reverse a string in C?
    a) strrev()
    b) strreverse()
    c) stringreverse()
    d) strrevrs()

String Operations – Continued

  1. What does the strcmp function return if str1 is lexicographically greater than str2?
    a) Positive value
    b) Negative value
    c) 0
    d) Undefined
  2. If str1 = "abc" and str2 = "def", what is the result of strcat(str1, str2);?
    a) "abcdef"
    b) "defabc"
    c) "abc def"
    d) Error
  3. Which function is used to copy only a specified number of characters from one string to another?
    a) strcpy()
    b) strncpy()
    c) strcat()
    d) strtrunc()
  4. Which function checks if two strings are equal in C?
    a) strcmp()
    b) strsame()
    c) strequal()
    d) strmatch()

Array of Strings – Continued

  1. What will strlen(arr[1]) return if arr is a 2D character array containing { "apple", "banana", "cherry" }?
    a) 6
    b) 7
    c) 5
    d) 3
  2. If char arr[2][6] = {"hello", "world"};, what is arr[1][4]?
    a) 'd'
    b) 'o'
    c) '\0'
    d) 'r'

QuestionAnswer
1a) An array is a collection of variables of the same type stored in contiguous memory locations
2c) arr[0]
3b) arr[4]
4b) float
5d) Index
6a) 0
7c) arr[2][2]
8c) arr[2][1]
9b) 6
10d) arr[3][2]
11a) sizeof(arr) / sizeof(arr[0])
12b) sizeof(arr) / sizeof(int)
13c) 2D array
14b) It has two dimensions
15c) sizeof(arr) / (sizeof(int) * 3)
16a) An array is a collection of elements of the same type
17d) 3
18a) Constant size
19b) int arr[10] = {0};
20c) Array elements can be accessed using the index
21c) Index starts from 0
22a) All elements must be of the same data type
23b) arr[2][1]
24a) arr[1][2]
25d) int arr[3] = {1, 2, 3};
26c) 3
27b) Character array
28a) Arrays must be initialized with curly braces {}
29d) 4
30b) 2
31a) Character array
32c) Constant values can be assigned to individual elements
33b) The memory location of the first element
34d) Subscript notation
35a) Array initialization is optional
36c) 6
37c) 40
38c) Undefined behavior
39d) O(1)
40b) Sets arr[5] to the value of arr[4]
41c) #include <string.h>
42c) \0
43b) Strings are character arrays terminated by \0
44a) strrev()
45a) Positive value
46a) "abcdef"
47b) strncpy()
48a) strcmp()
49a) 6
50a) 'd'

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top