ProgrammingHard
char a[5] = "hi"; printf("%d", a[4]); What is printed?
- A. 32
- B. garbage
- C. 104
- D. 0
Correct answer: D. 0
Elements left out of an initialiser are set to zero, so the unused tail of a is zero. Printing a[4] as an int gives 0.
More C Programming questions
- 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?
- char d[6] = "abc"; / we want strncat(d, "defgh", 5) with no overflow / What is the smallest size d needs?