October 22, 2024
Chicago 12, Melborne City, USA
C#

What is 'forward declaration' and the difference between 'typedef struct X' and 'struct X'?


I am a beginner in C programming and I know the difference between struct type declaration and typedef struct declaration. I came across to know an answer saying that if we define a struct like:

typedef struct { 
    some members;
} struct_name;

Then it will be like providing an alias to an anonymous struct (as it is not having a tag name). So it can’t be used for forward declaration. I don’t know what the forward declaration means.

Also, I wanted to know that for the following code:

typedef struct NAME { 
    some members;
} struct_alias;

Is there any difference between NAME and struct_alias? Or are both equal as
struct_alias is an alias of struct NAME ?

Furthermore, can we declare a variable of type struct NAME like these:

struct_alias variable1;

and/or like:

struct NAME variable2;

or like:

NAME variable3; 



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video