What does `*` mean in a C declaration of `typedef struct`?

I am looking at a structure Cwith some syntax that I have never seen before. The structure is as follows:

typedef struct structExample {
   int member1;
   int member2
} * structNAME;

I know that usually with a structure:

typedef struct structExample {
   int member1;
   int member2
} structNAME;

I could turn to a member of the second definition of structure, saying:

structNAME* tempStruct = malloc(sizeof(structNAME));
// (intitialize members)
tempstruct->member1;

What does this extra do *in the first structure definition and how can I refer to the members of the first structure definition?

+5
source share
5 answers

This means that the specific type is a pointer type. This is the equivalent way to declare a type:

struct structExample {
    int member1;
    int member2;
};
typedef struct structExample * structNAME;

You would use it as follows:

structNAME mystruct = malloc (sizeof (struct structExample));
mystruct->member1 = 42;
+4
source

typedef makes these two statements the same

struct structExample *myStruct;
structName myStruct;

This means a structNamepointer tostruct structExample

, , , . ,

typedef struct structExample * structExampleRef;

, struct structExample;

+2

structNAME struct structExample.

structNAME tempStructPtr = malloc(sizeOf(struct structExample));
tempStructPtr->member1 = 2;
+1

, typedef, TYPENAME VARIABLENAME typedef TYPENAME ALIASEDNAME.

VARIABLENAME, , . , , " " .

:

typedef int * my_int_pointer;

, int struct.

+1

(* structNAME) .

0

All Articles