ProgrammingVery hardProduct company OA
What is printed?
What is printed?
printf("%.1f", 1 ? 3 : 2.5);- A. 2.5
- B. 3
- C. Undefined: an int is passed for %f
- D. 3.0
Correct answer: D. 3.0
The second and third operands of ?: are brought to a common type by the usual arithmetic conversions, so the expression has type double even though the int branch is chosen. printf receives 3.0 and prints it with one decimal.
More C Programming questions
- What is printed? c int a = 0, b = 10; while (a < b) { a += 3; b -= 2; } printf("%d %d", a, b);
- After int q = realloc(p, 2 n sizeof q); succeeds (q is not NULL), where p pointed to n ints, which statement is true?
- With int i = 1, x; int a[5] = {0}; which of these statements have undefined behaviour? (i) i = i++ + 1; (ii) a[i] = i++; (iii) i = (i, i +…
- Which of the objects A to E have static storage duration (they live for the whole run of the program, in the data or BSS segment)? c int…
- What is printed? c int cmp(const void a, const void b) { return (const int )b - (const int )a; } int main(void) { int v[] = {4, 9, 1, 7}…
- What is printed? c printf("%d %d %d", atoi("42abc"), atoi(" -7x"), atoi("x9"));