AllInfoHub Logo

AllInfoHub – MCQ Practice

Arrays and Strings – Multiple Choice Questions (MCQs)

  1. 25. What does the `strcmp()` function return if the two strings are equal?

    • A. A positive value
    • B. A negative value
    • C. 0
    • D. 1
  2. 26. What does the `strcmp()` function return if the first string is lexicographically greater than the second?

    • A. A positive value
    • B. A negative value
    • C. 0
    • D. 1
  3. 27. What does the `strcmp()` function return if the first string is lexicographically smaller than the second?

    • A. A positive value
    • B. A negative value
    • C. 0
    • D. 1
  4. 28. What is the purpose of the `strncat()` function?

    • A. To concatenate at most n characters from one string to another
    • B. To compare the first n characters of two strings
    • C. To copy at most n characters from one string to another
    • D. To find the length of a string up to n characters
  5. 29. What is the purpose of the `strncpy()` function?

    • A. To copy at most n characters from one string to another
    • B. To concatenate at most n characters from one string to another
    • C. To compare the first n characters of two strings
    • D. To find the length of a string up to n characters
  6. 30. What is the purpose of the `strchr()` function?

    • A. To find the first occurrence of a character in a string
    • B. To find the last occurrence of a character in a string
    • C. To replace a character in a string
    • D. To count the occurrences of a character in a string
  7. 31. What is the purpose of the `strstr()` function?

    • A. To find the first occurrence of a substring within a string
    • B. To find the last occurrence of a substring within a string
    • C. To replace a substring within a string
    • D. To compare two substrings
  8. 32. Can you pass an entire array as an argument to a function in C?

    • A. Yes
    • B. No
    • C. Only by passing individual elements
    • D. Only by passing the size
  9. 33. When you pass an array to a function in C, what is actually passed?

    • A. A copy of the entire array
    • B. A copy of the first element
    • C. The memory address of the first element
    • D. The size of the array
  10. 34. What is the difference between passing an array by value and by reference to a function in C?

    • A. Arrays are always passed by reference (address)
    • B. Arrays are always passed by value (copy)
    • C. You can choose to pass by value or reference for arrays
    • D. There is no difference
  11. 35. What is a pointer to an array in C?

    • A. A variable that stores the address of the first element of the array
    • B. A variable that stores the size of the array
    • C. A variable that points to any element of the array
    • D. A special type of array
  12. 36. How do you declare a pointer to an integer array of size 5 in C?

    • A. int *ptr;
    • B. int (*ptr)[5];
    • C. int ptr[5]*;
    • D. pointer int[5] ptr;