ProgrammingHard
const char *s = "abcabc"; printf("%ld", (long)(strstr(s, "ca") - s)); What is printed?
- A. 1
- B. 3
- C. 4
- D. 2
Correct answer: D. 2
strstr returns a pointer to the first occurrence of "ca", which starts at index 2. Subtracting s gives the index.
More C Programming questions
- char d[4] = "abc"; printf("%zu", sizeof d - strlen(d)); What is printed?
- char s[] = "Hello"; for (char p = s; p; p++) if (p >= 'a' && p <= 'z') p -= 32; printf("%s", s); What is printed?
- int a, b; int n = sscanf("12-34", "%d-%d", &a, &b); printf("%d", b); What is printed?
- char s[10], w[10]; int n = 0; sscanf("abc123", "%[a-z]%d", s, &n); printf("%d", n); What is printed?
- char s[] = "a b,c"; int count = 0; for (char t = strtok(s, " ,"); t; t = strtok(NULL, " ,")) count++; printf("%d", count); What is printed?
- char s[] = "abc"; char t[sizeof s]; strcpy(t, s); t[0] = 'X'; printf("%s%s", s, t); What is printed?