ProgrammingHard
char s[] = "banana"; char *p = strrchr(s, 'a'); printf("%ld", (long)(p - s)); What is printed?
- A. 5
- B. 1
- C. 3
- D. 4
Correct answer: A. 5
strrchr returns a pointer to the last 'a', which is at index 5. Subtracting the base address gives that index.
More C Programming questions
- printf("%zu", strcspn("aXbYc", "XY") + strspn(" 42ab", " 0123456789")); What is printed?
- A naive strstr-style search looks for a pattern of length m = 50000 in a text of length n = 100000. The text is all 'a' and the pattern is…
- What does strncmp("abc", "xyz", 0) return?
- 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')?