ProgrammingModerate
printf("%d", (int)sizeof(char)); What is printed in C?
- A. 2
- B. 1
- C. 4
- D. 8
Correct answer: B. 1
The standard defines sizeof(char) as exactly 1 on every implementation, even where a char has more than 8 bits (CHAR_BIT > 8). 2 or 4 confuse it with a wide character or an int.
More C Programming questions
- 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…
- 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?