GATE Computer ScienceModerateGATE CS (PYQ pattern)
int a = 7, b = 2; float f = a / b + a / 2.0 + (float)(a / b) * b; printf("%.2f %d", f, (int)(a / b * 2.0)); What is printed?
- A. 12.50 6
- B. 13.50 7
- C. 14.00 6
- D. 9.50 6
Correct answer: A. 12.50 6
a / b = 3 (integer division); a / 2.0 = 3.5; (float)(a / b) * b = 3 * 2 = 6, so f = 3 + 3.5 + 6 = 12.5. The cast of a / b * 2.0 gives (3 * 2.0) = 6.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int a = 5, b = 3, c = 2; int x = a + b << c > 20; int y = 6 & 3 == 3; int z = 1 + 2 3 % 4 - 5 / 2 | 8 >> 2; printf("%d %d %d", x, y, z)…
- int C(int n, int k) { if (k == 0 || k == n) return 1; if (k == 1) return n; return C(n - 1, k - 1) + C(n - 1, k); } How many calls to C…
- Elements 1, 2, 3, 4, 5, 6 are pushed in this order onto a stack, with pops allowed at any time until all are popped. Of all possible…
- An input-restricted double-ended queue lets items 1, 2, 3, 4, 5 be inserted only at the rear (in that order) while removals are allowed at…
- A hash table has 7 slots (0 to 6) and uses linear probing with h(k) = k mod 7. The six keys 8, 15, 3, 10, 5, 12 are inserted in some…
- The distinct keys 1..8 are arranged as a max-heap in a 0-indexed array of size 8 (children of i at 2i+1, 2i+2). Over all valid max-heaps…