ProgrammingModerate
In C (not C++), what is sizeof('A')?
- A. 1 byte, like sizeof(char)
- B. 2 bytes, always
- C. sizeof(int), which is usually 4 bytes
- D. sizeof(char) plus padding
Correct answer: C. sizeof(int), which is usually 4 bytes
A character constant has type int in C, so sizeof('A') equals sizeof(int). In C++ it would be char and give 1.
More C Programming questions
- char a[5] = "hi"; printf("%d", a[4]); What is printed?
- int n = -1; if (n < strlen("abc")) puts("yes"); else puts("no"); What is printed?
- int v = 0; for (const char p = "-42"; p >= '0' && p <= '9'; p++) v = v 10 + (p - '0'); printf("%d", v); What is printed?
- char d[4]; strncpy(d, "abcdef", 4); / d now has no terminator / Which call is safe to print d with?
- char s[] = "x=1;y=2"; char t = strtok(s, "="); printf("%s %zu", t, strlen(s)); What is printed?
- Given char names[] holding strings, which qsort comparator sorts them alphabetically?