I was curious to know how exactly typedef works.
typedef struct example identifier;
identifier x;
In above statement is ‘identifier’ just replaced (somethings like string replacement) with ‘struct example’ in code? If no, what does typedef do here?
please enlighten!
No, it is not a string replacement – that would be macros. It creates an alias for the type.
typedefs are preferred over macros for custom types, in part because they can correctly encode pointer types.