ProgrammingHardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {1, 2, 2, 3, 1, 4};
int c = 0;
for (int i = 0; i < 5; i++)
if (a[i] < a[i + 1]) c++;
printf("%d", c);
}- A. 2
- B. 3
- C. 4
- D. 5
Correct answer: B. 3
The adjacent pairs are (1,2), (2,2), (2,3), (3,1) and (1,4), and the strictly increasing ones are (1,2), (2,3) and (1,4). Counting non-strict increases would give 4.
More C Programming questions
- For uint32t a = 5 and b = 3, how many of these statements are true? (i) a - b > a (ii) (a - b) + b == a (iii) ~a == UINT32MAX (iv) a / b b…
- What is printed? c #include <stdio.h> int main(void) { int a[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) a[i][j] = i 4…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xABCD; printf("%u", (x >> 5) & 7u); }
- What is printed? c #include <ctype.h> #include <stdio.h> int main(void) { const char s = "Hello World"; int n = 0; for (const char p = s…
- What is printed? Assume int is 4 bytes and a pointer is 8 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof(int[10]) /…
- What is printed? Assume unsigned long long is 64 bits. c #include <stdio.h> int main(void) { printf("%llu", (1ULL << 63) 2); }