I was using my structure like this. I don’t like to typedef as I have told it can hide errors.
However, I was looking at some sample code and I have seen structures declared like this. And this is the normal way I declare them.
struct person
{
int age;
char name[32];
};
using like this:
struct person person_a;
person_a.age = 20;
etc.
However, I have seen structures declared like this:
struct
{
int age;
char name[32];
}person;
and
struct _person
{
int age;
char name[32];
}person;
What is the difference between all these different techniques, and how would you decide when it is the best to use each particular one.
Many thanks for any suggestions,
This:
declares a variable
personthat is astruct. Thestructhas no name, but you still use thepersonvariable the same way.This is identical to:
It declares a
structnamed_personand then makes a variable calledpersonof typestruct _person.