To define a struct in the C language, it is best to use TypeDef, and the typedef is actually a new name for our struct that defines a new type, and when you write your own code, you can directly use the new type first variable that you define.
For example
#include <stdio.h>typedef struct{ int num; struct Node *next;} Node;int Main () { Node n; n.num=111; printf ("%d", n.num); return 0;}
By using TypeDef, we define the struct as the new struct type--node, and when used later, you can define the variable directly using Node.
#include <stdio.h>struct node{ int num; struct Node *next;}; int main () { struct Node n; n.num=111; printf ("%d", n.num); return 0;}
However, when we declare a variable later in the absence of a TypeDef, we must indicate that node is a struct, otherwise the compiler does not know the existence of a node type variable.
In short, in C language, typedef is a struct XX from an alias, convenient to write later.
But in C + +, there is no such requirement.
#include <iostream>using namespace std;struct node{ int num; Node *next;}; int main () { Node n; n.num=111; cout<<n.num; return 0;}
Visible, in C + +, once the struct is declared as a new type, it can be used directly later.
about typedef in the C language