ProgrammingVery hardGATE CS · Campus placements
char s[] = "a\0b"; What is strlen(s)?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: C. 1
strlen stops at the first null byte, which here is the embedded one after a. The array holds four bytes in total, but the string length is 1.
More C Programming questions
- uint32t v = 0; for each digit d of the decimal string "4294967296", v = v 10 + d; What is v at the end?
- Using fib-like recursion where a stair can be climbed by 1 or 2 steps, the number of ways for 10 stairs is the recursion W(n) = W(n-1) +…
- What is sizeof "hi" in C?
- For unsigned a and b greater than 0 stored in uint32t, which test correctly detects that a b overflows?
- char words[] holds strings and must be sorted by length first and then alphabetically using qsort. Which comparator is correct?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); What is n?