Which statement about strdup() is true?
strdup(s) allocates a copy of s with malloc() and returns it; you must free() it. It was a POSIX function for decades and was added to ISO C in C23, together with strndup().
Strings · Exercise 1 of 4
Twelve multiple-choice questions on how C strings work: the terminator, literals vs arrays, safe input, string.h, ctype, UTF-8 and C23. Pick an option to check your answer instantly.
Which statement about strdup() is true?
strdup(s) allocates a copy of s with malloc() and returns it; you must free() it. It was a POSIX function for decades and was added to ISO C in C23, together with strndup().
What does a == b compare when a and b are strings?
Both names become pointers, so == asks whether they point to the same place. To compare the text, use strcmp(a, b) == 0.
Timed online tests with instant scores and explanations.