ProgrammingHard
char buf[8] = "12345"; buf[strlen(buf) - 1] = '\0'; printf("%s", buf); What is printed?
- A. 12345
- B. 1235
- C. 5
- D. 1234
Correct answer: D. 1234
strlen is 5, so the index 4 holds the last digit, which is replaced by the terminator. The string becomes 1234.
More C Programming questions
- char s[] = "abc"; printf("%c", s[sizeof s - 1]); What is printed?
- printf("%d", (int)sizeof(char)); What is printed in C?
- char w[] = "one two"; char p = w; while (p && p != ' ') p++; printf("%d", (int)(p - w)); What is printed?
- 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…