+ 3
In typedef struct what is name of struct here ?
typedef struct { int id; char title[40]; float hours; } course, c, cpp; In this the struct have three names or not if no then c and cpp are variable?
2 odpowiedzi
+ 5
course c and cpp three names for the same structure
https://stackoverflow.com/questions/30370036/how-a-struct-being-typedef-ed-to-multiple-names
+ 4
`typedef` defines type alias(es), so in your type definition code above, all the 3 <course>, <c> and <cpp> are type aliases for the defined struct. Later on you can use either one of the 3 to define a variable of that struct type.
For example;
#include <stdio.h>
typedef struct
{
int id;
char title[40];
float hours;
} course, c, cpp;
int main()
{
course x = { 942020, "Generic", 942.020 };
c y = { id: 123, title: "C language", hours:456 };
cpp z = { 1098, "C++", 10.98 };
printf("%d %s %.3f\n%d %s %.2f\n%d %s %.2f\n", x.id, x.title, x.hours, y.id, y.title, y.hours, z.id, z.title, z.hours);
return 0;
}