Explanation
The correct answer is (b) 9.
Explanation
This function calculates the length of a string by using pointer arithmetic.
Initialization: The pointer str2 is initialized to point to the same starting memory address as str1.
Pointer Traversal: The while (*++str1) loop increments the str1 pointer until it reaches the null terminator ('\0') at the end of the string.
Pointer Arithmetic: The final return (str1 - str2); calculates the number of characters between the end pointer (str1) and the start pointer (str2).
Conceptual Mathematical Model
Let the starting address be Astart and the address of the null terminator be Aend. The pointer arithmetic operation performs:
Length=Aend−Astart
For the string "GeeksQuiz", the number of characters is 9. Therefore, the difference between the final position of str1 and the initial position str2 is:
str1−str2=9
Since the calculation resolves to the count of characters before the null character, the program outputs 9.