ProgrammingHardProduct company OA
What is printed?
What is printed?
const char *s = "abcabcab";
const char *p = strstr(s, "cab");
printf("%td %s %td", p - s, p + 3, strstr(p + 1, "cab") - s);- A. 2 abcab 5
- B. 2 cab 5
- C. 5 cab 5
- D. 2 cab 2
Correct answer: B. 2 cab 5
The first "cab" starts at index 2. p + 3 is index 5, which prints "cab" to the end. Searching again from p + 1 skips the first match and finds the next "cab" at index 5. Searching from p itself would find index 2 again.
More C Programming questions
- What is printed? c struct A { int v[3]; }; struct A make(void) { struct A a = {{1, 2, 3}}; return a; } int main(void) { struct A x =…
- What is printed? c const char s = "a1b2c3d4"; int sum = 0; for (; s; s++) { if (s >= 'a') continue; if (s == '3') break; sum += s - '0'; }…
- What is printed? c int s = 0; for (int i = 0; i < 5; i++) { switch (i) { case 1: continue; case 3: break; default: s += 10; } s += i; }…
- What is printed? c int a[] = {10, 20, 30}; printf("%d", a[1, 2]);
- What is printed? c struct P { int x; int y; } p = {7, 9}; int q = (int )&p; printf("%d", q);
- What is printed? c int p(int n, int m) { / ways to write n as a sum of parts <= m / if (n == 0) return 1; if (n < 0 || m == 0) return 0…