• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Quiz - 112 | Question 4

Pick the best statement for the below program: 

C
#include <stdio.h>

int main()
{
    struct {
        int i;
        char c;
    } myVar = {.i = 100, .c = 'A'};
    
    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

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments