Reputation: 29064
I know the diff between struct and struct with typedef keyword in front. The reference is this: typedef struct vs struct definitions
struct myStruct{
int one;
int two;
};
vs
typedef struct{
int one;
int two;
}myStruct;
But what is the diff between this two types:
struct point {
int x;
int y;
};
vs
struct point {
int x;
int y;
} my_point;
One more:
typedef struct set_t{
int count;
void **values;
} *SetRef;
what is this type?
Upvotes: 0
Views: 229
Reputation: 939
The first one only declares the structure. You will have to use it later to create an object of it later. The second one declares the structure and a object of it at the same time.
Upvotes: 1
Reputation: 145829
struct point { int x; int y; };
This declares a new type struct point
with two int
members x
and y
.
struct point { int x; int y; } my_point;
This also declares a new type struct point
with two int
members x
and y
and this declares an object my_point
of type struct point
.
Upvotes: 2
Reputation: 5456
In the second, you also define a varibale (named my_point
) from the type struct point
.
Upvotes: 1
Reputation: 46183
The first declares a struct
type, while the second one declares both the type and an instance my_point
. In other words, my_point
is not a type, but rather an actual struct point
instance.
Upvotes: 1