Skip to main content

Different between struct and typedef struct

#include<stdio.h>
struct type1{
int data;
};

typedef struct type{//type is optional
int data;
} type2;

//self pointer
typedef struct self{
int data;
type3* pointer;//wrong
self* pointer;//wrong
struct self* pointer;
}type3;
//splitting above
struct self{
int data;
struct self* pointer;
};
typedef struct self type4;


int main(){
//Declaration
type1 variable1;//wrong
struct type1 variable2;//Correct

type variable3;//wrong
struct type variable3;//correct

type2 variable3;//correct
struct type2 variable3;//wrong

return 0;
}