ProgrammingHard
What does strncmp("abc", "xyz", 0) return?
- A. a negative value
- B. a positive value
- C. a value that depends on the strings
- D. 0
Correct answer: D. 0
strncmp compares at most n characters. With n = 0 nothing is compared, so the strings count as equal and zero is returned.
More C Programming questions
- char a[3] = {'x', 'y', 'z'}; Which call reads a correctly with no undefined behaviour?
- char a = "", b = "abc"; if (strlen(a) - strlen(b) > 0) puts("longer"); else puts("not longer"); What is printed?
- In C (not C++), what is sizeof('A')?
- char a[5] = "hi"; printf("%d", a[4]); What is printed?
- int n = -1; if (n < strlen("abc")) puts("yes"); else puts("no"); What is printed?
- int v = 0; for (const char p = "-42"; p >= '0' && p <= '9'; p++) v = v 10 + (p - '0'); printf("%d", v); What is printed?