ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {1, 3, 2, 5}, c = 0;
for (int *p = a; p < a + 4; p++)
if (*p > 2) c++;
printf("%d", c);
}- A. 1
- B. 3
- C. 2
- D. 4
Correct answer: C. 2
Only 3 and 5 exceed 2, so the pointer loop counts two elements.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int x = 0, p = &x; p++ = 5; printf("%d", x); }
- What is printed? c #include <stdio.h> int main(void) { const char s = "abc"; printf("%d", s[3] == '0'); }
- What is printed? c #include <stdio.h> int main(void) { int v[] = {-1, -2, -3}; unsigned s = 0; for (int i = 0; i < 3; i++) s +=…
- How many zero bits are there in the low eight bits of 0xF0? Count them with this program. c #include <stdio.h> int main(void) { unsigned x…
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void a, const void b) { const char x = (const…
- How many ordered ways are there to write 10 as a sum of 1s and 4s? Compute with this program. c #include <stdio.h> int f(int n) { if (n ==…