C Language Storage Classes typedef

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Defines a new type based on an existing type. Its syntax mirrors that of a variable declaration.

/* Byte can be used wherever `unsigned char` is needed */
typedef unsigned char Byte;

/* Integer is the type used to declare an array consisting of a single int */
typedef int Integer[1];

/* NodeRef is a type used for pointers to a structure type with the tag "node" */
typedef struct node *NodeRef;

/* SigHandler is the function pointer type that gets passed to the signal function. */
typedef void (*SigHandler)(int);

While not technically a storage class, a compiler will treat it as one since none of the other storage classes are allowed if the typedef keyword is used.

The typedefs are important and should not be substituted with #define macro.

typedef int newType; 
newType *ptr;        // ptr is pointer to variable of type 'newType' aka int

However,

#define int newType
newType *ptr;        // Even though macros are exact replacements to words, this doesn't result to a pointer to variable of type 'newType' aka int


Got any C Language Question?