0

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?

Community
  • 1
  • 1
lakshmen
  • 28,346
  • 66
  • 178
  • 276

5 Answers5

2
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.

ouah
  • 142,963
  • 15
  • 272
  • 331
2

my_point is a variable of type struct point.

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
1

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.

Platinum Azure
  • 45,269
  • 12
  • 110
  • 134
1

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

asaelr
  • 5,438
  • 1
  • 16
  • 22
1

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.

Gargi Srinivas
  • 929
  • 6
  • 6