ProgrammingHard
Which statement about the value returned by strcmp("apple", "Apple") is guaranteed by the C standard?
- A. It is positive, because 'a' (97) compares greater than 'A' (65), though its exact magnitude is implementation-defined
- B. It is exactly 32, the difference between 'a' and 'A'
- C. It is zero, because the comparison ignores case
- D. It is negative, because 'A' is listed before 'a'
Correct answer: A. It is positive, because 'a' (97) compares greater than 'A' (65), though its exact magnitude is implementation-defined
The standard only promises a value less than, equal to or greater than zero. The sign is fixed by the first differing unsigned characters, but the magnitude is not specified.
More C Programming questions
- char s[] = "abcdef"; memmove(s + 2, s, 4); printf("%s", s); What is printed?
- char a[10] = "hi"; printf("%zu", sizeof(a) - strlen(a) - 1); What is printed?
- char s[] = "xyz"; char p = s; p[0] = 'a'; printf("%s %zu", s, sizeof s); What is printed?
- char b[4]; int r = snprintf(b, 4, "%d", 123456); printf("%d %s", r, b); What is printed?
- int pal(const char s) { int i = 0, j = (int)strlen(s) - 1; while (i < j) if (s[i++] != s[j--]) return 0; return 1; } How many of "a"…
- char s[] = "xyz"; for (int i = 0; s[i]; i++) s[i] = (s[i] - 'a' + 3) % 26 + 'a'; printf("%s", s); What is printed?