Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying the parts of this typedef struct in C?

Tags:

c

syntax

Please help me identify the parts of this typdef and what each part does and how it can be used:

typedef struct my_struct
{
        int a;
        int b;
        int c;
} struct_int, *p_s;

struct_int struct_array[5];

What I think they are, pleae correct if wrong:

  1. typedef struct is creating a new type.
  2. my_struct is the name of this type but not used in the rest of the code.
  3. struct_int is one instance of the type that we can use in the code.
  4. *p_s is the pointer specifically to the one instance we created.
  5. struct_array is an array of the instance we created. (This part confuses me since we already created an instance...)

Also, when creating the array of structs, why do we use struct_int instead of my_struct?

like image 757
T.T.T. Avatar asked Dec 10 '22 01:12

T.T.T.


1 Answers

struct my_struct is a name of a type, my_struct is a tag name and not a type.

typedef does not create types in C, but creates alias names for existing types.

like image 167
ouah Avatar answered Dec 21 '22 23:12

ouah