ProgrammingHardTCS NQT · Infosys
Which statement about the return value of strcmp is true?
- A. strcmp returns exactly -1, 0 or 1
- B. strcmp returns a negative, zero or positive value, and the standard fixes only the sign
- C. strcmp returns the length difference of the two strings
- D. strcmp is undefined when the strings are equal
Correct answer: B. strcmp returns a negative, zero or positive value, and the standard fixes only the sign
The standard promises only the sign of the result, so code must test with less than zero and greater than zero. Assuming exactly -1, 0 or 1 breaks on some platforms.
More C Programming questions
- For 4-bit masks (bits 0 to 3), how many masks have both bit 0 and bit 2 set?
- What is the value of (1ULL << 63) >> 62 for uint64t arithmetic?
- uint8t a = 200, b = 250; uint8t avg = (a + b) / 2; What is avg?
- What is the value of 1 + 2 3 << 1 in C?
- How many positive divisors does 40 have?
- int next(void) { static int c = 0; return ++c; } Each of three calls returns its value, and the three returns are added together. What is…