ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
const char *s = "112233";
int count[10] = {0};
for (const char *p = s; *p; p++)
count[*p - '0']++;
printf("%d", count[2]);
}- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Each character's digit value indexes the count array, and the digit 2 occurs twice in 112233.
More C Programming questions
- What is the trace of the matrix product A B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program. c #include…
- How many elements of {0, 2, 1, 3, 4, 7, 6} equal their own index? Count with this program. c #include <stdio.h> int main(void) { int a[] =…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {2, 7, 1}; int e = a + sizeof a / sizeof a[0] - 1; printf("%d", e); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int a[4]; printf("%ld", (long)((char )&a[2] - (char…
- How many valid strings of n = 3 pairs of parentheses are there? The program counts them recursively. What is printed? c #include <stdio.h>…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { return (const unsigned char )a - (const…