Top

Discussion

Pick the best statement for the below program:

#include "stdio.h"
 
int main()
{
 struct {int i; char c;} myVar = {.c ='A',.i = 100};
 printf("%d %c",myVar.i, myVar.c);
 return 0;
}

 

  • A.Compile error because struct type (containing two fields of dissimilar type i.e. an int and a char) has been mentioned along with definition of myVar of that struct type.
  • B.Compile error because of incorrect syntax of initialization of myVar. Basically, member of operator (i.e. dot .) has been used without myVar.
  • C.Compile error for not only B but for incorrect order of fields in myVar i.e. field c has been initialized first and then field i has been initialized.
  • D.No compile error and it’ll print 100 A.

Answer: D

No answer description available for this question.

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

Post your comment