What is the output of this program?
#include <stdio.h>
struct result{
char sub[20];
int marks;
};
void main()
{
struct result res[] = { {"Maths",100},
{"Science",90},
{"English",85}
};
printf("%s ", res[1].sub);
printf("%d", (*(res+2)).marks);
}
Answer: B
Correct answer: Science 85
res[1].sub is the second element’s subject, Science. (*(res+2)).marks is the same as res[2].marks - the third element - which is 85. Both subscripts count from 0.
Please log in or register to report this question.