Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

C Quiz – 112 | Question 4

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Pick the best statement for the below program: 


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


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.


Compile error because of incorrect syntax of initialization of myVar. Basically, member of operator (i.e. dot .) has been used without myVar.


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.


No compile error and it’ll print 100 A.

Answer: (D)


As per C language, initialization of a variable of complete data type can be done at the time of definition itself. Also, struct fields/members can be initialized out of order using field name and using dot operator without myVar is ok as per C. Correct answer is D.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads