ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
int x = 7 / 2 * 2.0;
double y = 7 / 2.0 * 2;
printf("%d %.1f", x, y);- A. 7 7.0
- B. 6 7.0
- C. 7 6.0
- D. 6 6.0
Correct answer: B. 6 7.0
Evaluation is left to right: 7 / 2 is integer division (3) before the 2.0 appears, so x = 6.0, stored as 6. In y, 7 / 2.0 is already 3.5, and 3.5 * 2 = 7.0.
More C Programming questions
- What is printed? c void move(int pp) { (pp)++; pp += 10; } int main(void) { int a[] = {1, 2, 3}; int p = a; move(&p); move(&p); printf("%d…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xABCD; printf("%X %X", (x >> 4) & 0xF, (x & ~(0xFu << 8)) | (0x3u << 8));
- In C99, which declaration lets you allocate a rows × cols matrix of int (cols known at run time) with ONE malloc, use it as m[i][j], and…
- With 4-byte int, what is printed? c int a[4]; memset(a, 1, sizeof a); printf("%d", a[0]);
- What is printed? c struct N { int v; struct N nx; }; struct N c = {3, NULL}, b = {2, &c}, a = {1, &b}; struct N prev = NULL, cur = &a, nx…
- After this code, what does buf hold and what is n? c char buf[20]; int n = sprintf(buf, "%04d|%.2s", 7, "xyz");