Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the following C code?

char str1[] = "Helloworld ";
char str2[] = "Hello";
len = strspn(str1, str2);
printf("Length of initial segment matching %d\n", len );

 

  • A.6
  • B.5
  • C.4
  • D.no match

Answer: B

Correct answer: 5

strspn returns the length of the initial run of str1 made up only of characters from str2. The set is {H, e, l, o}, and Hello uses nothing else - but the sixth character, w, is not in the set, so the run stops there. The answer is 5.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.