Which header must be included to use sqrt()?
<math.h> declares the mathematical functions. (<cmath> is the C++ name.)
C Library Functions · Exercise 1 of 4
Twelve multiple-choice questions on header files, math, string, stdlib, ctype and time functions and their return values. Pick an option to check your answer instantly.
Which header must be included to use sqrt()?
<math.h> declares the mathematical functions. (<cmath> is the C++ name.)
In which header are qsort() and bsearch() declared?
Both general-purpose algorithms are in <stdlib.h>, together with malloc, strtol and exit.
What does #include <string.h> actually bring into your program?
The compiler needs the declarations to check calls; the linker supplies the implementation from the library.
Which statement about main() is true?
The standard library declares no main. A hosted program must define it, and the C runtime calls it after initialisation.
What does strcmp(s1, s2) return when s1 comes before s2?
The standard only promises the sign. Test strcmp(a, b) < 0, never == -1.
What is strlen("hello")?
strlen counts characters before '\0'. Storing the string needs strlen + 1 bytes; sizeof "hello" is 6.
Source and destination overlap. Which function copies the bytes correctly?
memmove works as if copying through a temporary buffer. memcpy and strcpy with overlapping regions are undefined behaviour.
What is the purpose of srand(time(NULL));?
The same seed always gives the same sequence (useful for tests). Seed once at the start; reseeding with the same second repeats numbers.
What is the difference between abs() and fabs()?
abs(-2.7) converts the argument to int and returns 2. Use fabs for floating values, labs/llabs for long types.
Which statement about strtok() is true?
Pass a writable array on the first call and NULL on later calls. Adjacent delimiters are skipped, so "a,,b" gives two tokens.
Timed online tests with instant scores and explanations.