ProgrammingHardTCS NQT · Infosys
int x = 5; x = x++; What is the outcome of this statement?
- A. x becomes 6
- B. x becomes 5
- C. undefined behaviour
- D. x becomes 7
Correct answer: C. undefined behaviour
x is modified twice between sequence points, once by the increment and once by the assignment, so the standard gives no defined result. Compilers may print any value.
More C Programming questions
- uint16t h = 0; for each character c of "ABCDE", h = h 31 + c; with 65 for 'A' and so on. What is h at the end?
- Which function correctly tests whether an unsigned value x is a power of two, with x = 0 excluded?
- char b[6]; snprintf(b, sizeof b, "%s-%d", "abcdef", 12345); int r = snprintf(NULL, 0, "%s-%d", "abcdef", 12345); printf("%s %d", b, r)…
- char b[5]; / stdin holds the nine bytes: abcdefgh and a newline / int calls = 0; do { fgets(b, sizeof b, stdin); calls++; } while…
- char s[] = "a,,b,c"; int n = 0; for (char t = strtok(s, ","); t != NULL; t = strtok(NULL, ",")) n++; printf("%d", n); What is printed?
- char d[8] = "ab"; strncat(d, "cdefgh", 3); printf("%zu", strlen(d)); What is printed?