Machine-translated by Google. Questions are authored in English.
Top

Discussion

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);
}

 

  • A.Maths 100
  • B.Science 85
  • C.Science 90
  • D.Science 100

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.