TYPEDEF

this is used to define new data types. its main use is to define custom types for structures.

SYNTAX

ALIAS FOR EXISTING TYPE

typedef existingTypeName newTypeName;
typedef existing-type-name new-type-name_1, new_type_name_2, ..., new_type_name_n;

EXAMPLE USAGE

#include <stdio.h>

int main(int argc, char *argv[])
{
  typedef unsigned char uchar;                    //uchar is an alias for unsigned char
  uchar characterName = 'a';
  printf("character inside main: %c\n", characterName);
  
  return 0;
}

 * the uchar alias is now understood to be "unsigned char" in the main function

Last updated