ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int main(void) {
int arr[3] = {1, 2, 3};
int *p = arr;
for (int i = 0; i < 3; i++, p++) {
printf("%d ", *p);
}
}- A. 3 2 1
- B. 1 1 1
- C. 1 2 3
- D. 2 3 4
Correct answer: C. 1 2 3
The comma in the for-loop's increment clause `i++, p++` executes both expressions each iteration (both i and p advance together); p starts at arr and walks alongside i, printing arr[0], arr[1], arr[2] in order: 1 2 3.
More C Programming questions
- Assume 32-bit int. What is printed? c int x = 7; int y = x > 5 && x < 10 ? x 2 : x + 1; printf("%d", y);
- What happens when this runs? c int p = malloc(10 sizeof(int)); for (int i = 0; i <= 10; i++) { p[i] = i; } free(p);
- Assume 32-bit int. What is printed? c int a = 6; int b = a++ 2; printf("%d %d", a, b);
- What is printed? c #define MAXSIZE 100 #if MAXSIZE > 50 const char label = "large"; #else const char label = "small"; #endif printf("%s"…
- Assume 32-bit int. What is printed? c int x = 10; int p = &x; p += 5; p = 2; printf("%d", x);
- What happens when this runs? c int fibonacci(int n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } int main(void) {…