← Quiz: String Handling in C: all 15 questions
Quiz: String Handling in C · Question 11 of 15
What does this print? (code)
What does this print?
#include <stdio.h>
#include <stddef.h>
size_t my_len(const char *s) {
const char *p = s;
while (*p) p++;
return p - s;
}
int main(void) {
printf("%zu %zu\n", my_len("campus"), my_len(""));
return 0;
}
- A.7 1
- B.6 0
- C.6 1
- D.5 0
Answer & explanation
Correct answer: 6 0
p walks to the '\0', and the distance from the start is the number of characters before it.
Can you get the rest right without peeking?
Take the timed Quiz: String Handling in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →