ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int main(void) {
int n = 5;
int result = 1;
int i = 1;
while (i <= n) {
result *= i;
i++;
}
printf("%d", result);
}- A. 120
- B. 24
- C. 60
- D. 15
Correct answer: A. 120
This computes 5! iteratively: 1*1*2*3*4*5 = 120.
More C Programming questions
- Assume 32-bit int. What is printed? c int a = 4, b = 7; int max = (a > b) ? a : b; int min = (a < b) ? a : b; printf("%d %d %d", max, min…
- What happens when this runs? c int p; if (p != NULL) { printf("%d", p); } else { printf("null"); }
- Assume a 64-bit LP64 ABI. What is printed? c struct Inventory { char name[16]; int quantity; double price; }; void restock(struct…
- Assume 32-bit int. What is printed? c #define SWAP(a, b, type) do { type t = a; a = b; b = t; } while (0) int main(void) { int x = 1, y =…
- Assume 32-bit int. What is printed? c int x = 5, y = 3; int result = x++ - ++y; printf("%d %d %d", x, y, result);
- What is printed? c int main(void) { int a = 1, b = 2, c = 3, d = 4; int result = (a < b) ? ((c < d) ? 1 : 2) : ((c < d) ? 3 : 4)…