ProgrammingVery hard
int n = -1; if (n < strlen("abc")) puts("yes"); else puts("no"); What is printed?
- A. no
- B. yes
- C. undefined behaviour
- D. compile error
Correct answer: A. no
n is converted to size_t, a huge unsigned value, so n < 3 is false. The comparison is well defined and quietly wrong.
More C Programming questions
- 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?
- char b[16]; sprintf(b, "%d%%", 50); printf("%zu", strlen(b)); What is printed?