ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int i = 3.99;
int j = -3.99;
int k = (int)(0.29 * 100);
printf("%d %d %d", i, j, k);- A. 3 -4 29
- B. 3 -3 28
- C. 4 -4 29
- D. 3 -3 29
Correct answer: B. 3 -3 28
Converting a floating value to int truncates toward zero: 3.99 → 3 and -3.99 → -3 (not -4). 0.29 has no exact binary representation; the double nearest to it is slightly below 0.29, so 0.29 * 100 evaluates to 28.999999999999996 and truncation gives 28, not 29. Use round() or add 0.5 before converting when you mean rounding.
More C Programming questions
- What is printed? c / 4-byte int with 4-byte alignment / struct S { int a; char b; } arr[5]; printf("%td %td", &arr[4] - &arr[1], (char…
- What is printed? c char s[] = "abcdef"; char p = s + 2; p[1] = 'X'; printf("%s %s %c %zu", s, p, (p - 2), strlen(p + 4));
- What is printed? c int f(int n) { if (n <= 0) return 0; return n % 2 ? f(n - 1) + n : f(n / 2) 2; } int main(void) { printf("%d %d"…
- What is printed? c unsigned char x = 0x1D, r = 0; for (int i = 0; i < 8; i++) { r = (r << 1) | (x & 1); x >>= 1; } printf("%#x", r);
- What is printed? c int a = 2, b = 3, c = 4; printf("%d %d %d", a + b c % 5 - -a, a < b < c, c > b > a);
- What is printed? c char w[] = {"red", "green", "blue"}; char p = w + 1; printf("%c %s %c %zu", p, (p + 1) + 2, ((p - 1) + 1), strlen(p[1])…