AllInfoHub Logo

AllInfoHub – MCQ Practice

Arrays and Strings – Multiple Choice Questions (MCQs)

  1. 13. What is the size of the array 'arr' declared as `int arr[10];` (assuming int size is 4 bytes)?

    • A. 10 bytes
    • B. 20 bytes
    • C. 40 bytes
    • D. 80 bytes
  2. 14. What happens if you try to access an array element with an index out of bounds in C?

    • A. It will result in a compilation error
    • B. It will return 0
    • C. It might lead to undefined behavior
    • D. It will automatically resize the array
  3. 15. Can you initialize an array without specifying its size if you provide the initial values?

    • A. Yes
    • B. No
    • C. Only for character arrays
    • D. Only for integer arrays
  4. 16. What is a multi-dimensional array in C?

    • A. An array of pointers
    • B. An array where elements can be of different data types
    • C. An array of arrays
    • D. A special type of string
  5. 17. What is an array of strings in C?

    • A. A single string with multiple lines
    • B. A 2D character array
    • C. An array of character pointers
    • D. Both B and C
  6. 18. How do you declare an array of 5 strings, each with a maximum length of 20, in C?

    • A. char str[5][20];
    • B. string str[5][20];
    • C. char *str[5];
    • D. char str[20][5];
  7. 19. What is the purpose of the `gets()` function in C?

    • A. To get an integer input
    • B. To get a character input
    • C. To get a string input (though unsafe)
    • D. To print a string
  8. 20. Why is `gets()` considered unsafe to use?

    • A. It can lead to buffer overflows
    • B. It is slow
    • C. It cannot read strings with spaces
    • D. It is not available in all compilers
  9. 21. Which safer alternative is often used instead of `gets()` to read a string in C?

    • A. scanf()
    • B. printf()
    • C. fgets()
    • D. puts()
  10. 22. What does the `sizeof()` operator return when used with an array?

    • A. The number of elements in the array
    • B. The size of the first element
    • C. The total size of the array in bytes
    • D. The index of the last element
  11. 23. What does the `sizeof()` operator return when used with a string literal (e.g., `sizeof(\Hello\")`)?"""

    • A. The length of the string
    • B. The length of the string + 1 (for null terminator)
    • C. The size of a character pointer
    • D. 5
  12. 24. Can you compare two strings directly using the '==' operator in C?

    • A. Yes
    • B. No
    • C. Only if they are of the same length
    • D. Only if they are string literals