ProgrammingModerate
char w[] = "ab", z[2] = "ab"; printf("%zu", sizeof w + sizeof z); What is printed?
- A. 4
- B. 5
- C. 6
- D. 3
Correct answer: B. 5
w has three bytes with its terminator. z has exactly two bytes and no terminator, which is legal as long as no string function is called on it. 3 + 2 = 5.
More C Programming questions
- For a string s of length up to 2 x 10^5 stored in a char array, which in-place reversal is correct and fast enough?
- What is the value of sizeof("hello") in C?
- char buf[] = "abcn"; buf[strcspn(buf, "n")] = '0'; printf("%zu", strlen(buf)); What is printed?
- Why must the result of getchar() be stored in an int rather than a char?
- Which call reads a line into char buf[100] safely?
- char name[10]; / input: a long name / scanf("%9s", name); What is the most characters stored before the terminator?