Federica Guidotti
Federica Guidotti

Reputation: 169

Clarification about a particular struct definition in C

I found this structure in the slides of my professor:

struct point{
      int x;
      int y;
} p;

What does p mean? So far I used only the classical struct like this:

struct point{
      int x;
      int y;
};

Upvotes: 0

Views: 41

Answers (2)

Sai Kalyaan Palla
Sai Kalyaan Palla

Reputation: 1

struct point{
    int a;
    int b;
}p;

This is the same as using struct point p

When we use typedef struct p as in

typedef struct point{
    int a;
    int b;
}p;

We can use p to declare a structure pointer or structure variable later on

To create a structure pointer p *abc

To create a structure variable p xyz

Upvotes: -1

0___________
0___________

Reputation: 67476

struct point{
      int x;
      int y;
} p;

defines a variable p of type struct point

it is same as

struct point{
      int x;
      int y;
};
struct point p;

Upvotes: 3

Related Questions