ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {10, 20, 30};
int *p[] = {a, a + 1};
printf("%d", *p[1] + *(*p + 2));
}- A. 50
- B. 40
- C. 30
- D. 60
Correct answer: A. 50
*p[1] is a[1] = 20, and *p is a, so *(*p + 2) is a[2] = 30, giving 50. Grouping the star differently gives different elements.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 1 << 30 >> 28); }
- What is printed? A sorted int array {1, 3, 5, 7} is searched with bsearch for the key 6. c #include <stdio.h> #include <stdlib.h> int…
- How many subsets of {1, 2, 3, 4, 5} sum to exactly 10? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { int x = (const int )a, y = (const int )b…
- What is printed? c #include <stdio.h> int main(void) { unsigned s = 0; for (unsigned b = 1; b; b <<= 1) s += 1; printf("%u", s); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (3 & 1) == 1 ? 'y' : 'n'); }