ProgrammingHard
char w[] = "one two"; char *p = w; while (*p && *p != ' ') p++; printf("%d", (int)(p - w)); What is printed?
- A. 2
- B. 4
- C. 3
- D. 7
Correct answer: C. 3
The loop stops at the space, which is at index 3. The difference of the two pointers is that index.
More C Programming questions
- char s[] = "aXbXc"; int x = 0; for (int i = 0; s[i]; i++) x += s[i] == 'X'; printf("%d", x); What is printed?
- printf("%s", strcat(strcpy(buf, "ab"), "cd")); with char buf[10] declared before the call. What is printed?
- Records are sorted by name length first, then alphabetically, using qsort with a comparator on strlen and strcmp. Input names: bob, al…
- Records (x,5), (y,2), (z,5), (w,2), (v,9) are sorted by key with a stable sort, ascending. What is the order of names?
- The same five records are sorted by key with a stable sort in descending order. What is the order of names?
- In records (x,5), (y,2), (z,5), (w,2), (v,9), the index of the minimum key, choosing the first when there are ties, is which index?