Correct option is B
1.
str1: "Hello, IBPS!"
· The strlen(str1) function calculates the length of the string excluding the null terminator.
· Therefore, strlen("Hello, IBPS!") returns 12.
2.
str2: " "
· The strlen(str2) function calculates the length of the string including the single space character.
· Therefore, strlen(" ") returns 1.
3.
str3: ""
· The custom_strlen(str3) function calculates the length of the string using recursion.
· Since the string is empty, the base case *str == '\0' is true on the first call.
· Therefore, custom_strlen("") returns 0.
Important Key Points:
1.
String Length Calculation: The strlen function calculates the length of a string by counting the number of characters before the null terminator ('\0').
2.
Recursion in custom_strlen: The custom_strlen function demonstrates the use of recursion to calculate the length of a string.
3.
Null Terminator: The null terminator ('\0') marks the end of a string in C and is not included in the length returned by strlen.
Knowledge Booster:
1.
Recursive Functions: Understanding how recursion works is crucial for implementing functions that solve problems by breaking them down into smaller sub-problems.
2.
String Handling in C: Mastering string functions and memory management in C is essential for efficient and error-free programming.
3.
Edge Cases in String Handling: Recognizing edge cases, such as empty strings, helps in writing robust code that can handle various input scenarios.