ProgrammingVery hardGATE CS · Advanced
What is printed?
What is printed?
struct N { int v; struct N *nx; };
int main(void) {
struct N c = {3, 0}, b = {2, &c}, a = {1, &b};
struct N *p = &a;
p->nx->nx->v += p->v * 10;
(p = p->nx)->v *= 5;
printf("%d %d %d", a.v, b.v, c.v);
return 0;
}- A. 1 2 13
- B. 1 10 3
- C. 10 10 13
- D. 1 10 13
Correct answer: D. 1 10 13
The first statement adds 1 * 10 to c.v (13); then p moves to b and b.v is multiplied by 5, giving 10; a.v is untouched.
More C Programming questions
- What is printed? Assume C99 or later. c int g(int a, int b) { return b ? g(b, a % b) : a; } int main(void) { printf("%d %d", g(-48, 18)…
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main(void) { int i = 3, j = 1; int m = MAX(i++, j++); printf("%d %d %d"…
- In C, sizeof(char) is:
- Which storage class makes a local variable keep its value between calls to the function?
- The end of a C string is marked by:
- Which declaration makes p a pointer to an int?