This program is giving an error that name is outside aggregate initializer so how can we remove it? | SoloLearn: Learn to code for FREE!

+1

This program is giving an error that name is outside aggregate initializer so how can we remove it?

#include <stdio.h> struct student { int age; int grade; char name[40]; }; int main() { struct student s1 = { .grade = 9, .age = 19, .name = "John Birghimer"}; printf("Name: %s, Age: %d, Grade: %d\n", s1.name, s1.age, s1.grade); return 0; }

5/29/2020 9:34:40 AM

Saurabh Yadav

3 Answers

New Answer

+1

I am talking about dev c compiler, in dev c this program is not working

+1

Now I understand that you are getting a C++ compiler error on C code due to differences with structs between C and C++. Is your intention to convert the C code to run as a C++ program? If so, then I should defer to others here who have more DEV C++ experience. In the meantime, I will have to study and learn about this, myself.

0

The program worked perfectly for me when using the C compiler. Were you trying to compile it under C# (noting the c#struct keyword tag)?