ProgrammingVery hardProduct company OA
What is printed?
What is printed?
printf("%d %d", strncmp("abc", "abd", 2) == 0, strncmp("ab", "ab\0x", 5) == 0);- A. 1 0
- B. 0 0
- C. 1 1
- D. 0 1
Correct answer: C. 1 1
strncmp compares at most n characters and also stops at a '\0'. The first compares only "ab" with "ab". In the second both strings end after "ab" (the literal's '\0' hides the x), so they compare equal even though n is 5.
More C Programming questions
- uint8t a = 200, b = 100; uint8t c = a + b; What is the value of c?
- With uint32t x = 5u - 7u; what is the value of x?
- uint32t x = 0x00F0A8u; what is x & (0u - x) in hexadecimal?
- uint32t n = 0xB6u; the loop while (n) { n &= n - 1; count++; } runs with count starting at 0. What is count when the loop ends?
- uint16t v = 0xFFFFu; v = v << 4; What is v afterwards?
- For unsigned int n = 13, what is n ^ (n >> 1)? This is the binary-reflected Gray code of 13.