lakshmen
lakshmen

Reputation: 29064

Different types of Struct

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

Answers (5)

Gargi Srinivas
Gargi Srinivas

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

ouah
ouah

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

asaelr
asaelr

Reputation: 5456

In the second, you also define a varibale (named my_point) from the type struct point.

Upvotes: 1

Platinum Azure
Platinum Azure

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

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143061

my_point is a variable of type struct point.

Upvotes: 2

Related Questions