C | String | Question 4
Predict the output?
#include <stdio.h> int fun(char *str1) { char *str2 = str1; while(*++str1); return (str1-str2); } int main() { char *str = "GeeksQuiz"; printf("%d", fun(str)); return 0; } |
chevron_right
filter_none
(A) 10
(B) 9
(C) 8
(D) Random Number
Answer: (B)
Explanation: The function fun() basically counts number of characters in input string. Inside fun(), pointer str2 is initialized as str1. The statement while(*++str1); increments str1 till ‘\0’ is reached. str1 is incremented by 9. Finally the difference between str2 and str1 is returned which is 9.
Recommended Posts:
- C | String | Question 3
- C | String | Question 9
- C | String | Question 8
- C | String | Question 16
- C | String | Question 11
- C | String | Question 5
- C | String | Question 15
- C | String | Question 7
- C | String | Question 6
- C | String | Question 14
- C | String | Question 2
- C | String | Question 10
- C | String | Question 12
- C | String | Question 13
- C | String | Question 1



