ProgrammingHardProduct company OA
What is printed?
What is printed?
const char *s = " 42, 17";
printf("%zu %zu", strspn(s, " "), strcspn(s, ","));- A. 2 4
- B. 3 4
- C. 1 4
- D. 2 5
Correct answer: A. 2 4
strspn returns the length of the leading run made only of the given characters: two spaces. strcspn returns the length of the leading run that contains none of them: " 42" before the comma, 4 characters. '5' counts up to and including the comma.
More C Programming questions
- A header config.h is wrapped as #ifndef CONFIGH / #define CONFIGH / … / #endif. What problem does this prevent?
- With 4-byte int, after these lines run, which block can no longer be freed because no pointer to it remains? c int a = malloc(10…
- What is printed? c int pal(const char s, int i, int j) { if (i >= j) return 1; if (s[i] != s[j]) return 0; return pal(s, i + 1, j - 1); }…
- With 4-byte int, what is printed? c typedef int Row[3]; Row m[2] = {{1, 2, 3}, {4, 5, 6}}; Row p = m; printf("%zu %d", sizeof(Row)…
- What is printed? c int a = 0, b = 0, c = 0; if ((a = 2) && (b = 0) || (c = 3)) a++; printf("%d %d %d", a, b, c);
- Which line has undefined behaviour? c char a[] = "hi"; char p = "hi"; a[0] = 'H'; / (i) / p[0] = 'H'; / (ii) / char q = a; q[1] = 'I'; /…