ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int a = 1, b = 2, c = 3;
int *arr[3] = {&a, &b, &c};
int **p = arr;
for (int i = 0; i < 3; i++) {
**(p + i) *= 10;
}
printf("%d %d %d", a, b, c);- A. 10 20 30
- B. 1 2 3
- C. 10 2 3
- D. 1 20 30
Correct answer: A. 10 20 30
p+i steps through arr, each *(p+i) is one of the stored pointers, and **(p+i) dereferences through to a, b or c in turn, multiplying each by 10.
More C Programming questions
- What is printed? (undefined behavior aside, assume typical stack layout where locals of adjacent calls can overlap after return) c int…
- What is printed? c char arr[] = {"one", "two", "three"}; char p = arr; printf("%s %c %s", p, ((p + 1) + 1), p[2]);
- What is printed? Assume 32-bit int. c int flags = 0; flags |= (1 << 2); flags |= (1 << 4); flags &= ~(1 << 2); printf("%d", flags);
- What can be said about this program? c #include <stdlib.h> int main(void) { int p = malloc(sizeof(int)); free(p); free(p); }
- What is printed? c void modify(int arr[10]) { printf("%lu ", sizeof(arr)); } int main(void) { int a[10]; printf("%lu ", sizeof(a))…
- What is printed? const qualifies what p points to, not p itself. c int x = 5, y = 10; const int p = &x; p = &y; printf("%d", p);