AllInfoHub Logo

AllInfoHub – MCQ Practice

Arrays and Strings – Multiple Choice Questions (MCQs)

  1. 37. What is the relationship between array names and pointers in C?

    • A. The array name itself acts as a constant pointer to the first element of the array
    • B. Array names and pointers are completely different
    • C. You can only access array elements using pointers
    • D. Pointers cannot point to arrays
  2. 38. What is pointer arithmetic in the context of arrays in C?

    • A. Performing mathematical operations on array elements
    • B. Performing mathematical operations on the indices of the array
    • C. Performing mathematical operations on the memory addresses pointed to by array pointers
    • D. Accessing array elements using pointer notation
  3. 39. If `int arr[5];` and `int *ptr = arr;`, what does `ptr + 2` point to?

    • A. The first element
    • B. The second element
    • C. The third element
    • D. The address after the last element
  4. 40. What is a string literal in C?

    • A. A string variable
    • B. A constant string enclosed in double quotes
    • C. A character constant
    • D. An array of integers
  5. 41. Are string literals modifiable in C?

    • A. Yes
    • B. No
    • C. It depends on the compiler
    • D. Only if they are assigned to a character array
  6. 42. What happens if you try to modify a string literal directly in C?

    • A. It will result in a compilation error
    • B. It might lead to undefined behavior (segmentation fault)
    • C. The modification will be successful
    • D. The string literal will be copied to a modifiable location
  7. 43. What is the difference between `char str[] = \Hello\";` and `char *str = \""Hello\"";`?"""

    • A. The first declares a character array
    • B. the second declares a character pointer pointing to a string literal
    • C. Both are the same
    • D. The first declares a character pointer
  8. 44. Which of the following is a valid way to access the character at index 3 of the string \World\"?"""

    • A. \"World\""[3]"
    • B. World'[3]
    • C. *(\"World\"" + 3)"
    • D. All of the above
  9. 45. What is the purpose of the `<string.h>` header file?

    • A. It contains declarations for standard input/output functions
    • B. It contains declarations for mathematical functions
    • C. It contains declarations for string manipulation functions
    • D. It contains declarations for character handling functions
  10. 46. Which function can be used to find the first occurrence of a string within another string (case-insensitive)?

    • A. strstr()
    • B. stristr() (non-standard)
    • C. strcasestr() (non-standard)
    • D. Both B and C
  11. 47. What is the purpose of the `sprintf()` function?

    • A. To print formatted output to the console
    • B. To read formatted input from the console
    • C. To write formatted output to a string
    • D. To read formatted input from a string
  12. 48. What is the purpose of the `sscanf()` function?

    • A. To print formatted output to the console
    • B. To read formatted input from the console
    • C. To write formatted output to a string
    • D. To read formatted input from a string