ProgrammingModerate
char name[8] = "Sam"; printf("%d %d", (int)sizeof name, (int)strlen(name)); What is printed?
- A. 3 3
- B. 8 3
- C. 8 4
- D. 4 3
Correct answer: B. 8 3
The array holds eight bytes including the padding, and the string has three characters.
More C Programming questions
- char s[] = "12345"; int v = 0; for (int i = 0; s[i]; i++) v = v 10 + (s[i] - '0'); printf("%d", v); What is printed?
- char s[] = "ab"; char q = s + 2; printf("%d", q); What is printed?
- char c = 'A'; printf("%d %c", c + 1, c + 1); What is printed?
- printf("%s", "abc" + 1); What is printed?
- char name[] = "Bob"; char p = name; printf("%c%c", p[0], (p + 2)); What is printed?
- char buf[] = "ab"; buf[2] = 'c'; printf("%zu", sizeof buf); What is printed?