Example of typedef in C

typedef long long ll;

Below is the C program to illustrate how to use typedef.

C




// C program to implement typedef
#include <stdio.h>
 
// defining an alias using typedef
typedef long long ll;
 
// Driver code
int main()
{
    // using typedef name to declare variable
    ll var = 20;
    printf("%ld", var);
 
    return 0;
}


Output

20

C typedef

The typedef is a keyword that is used to provide existing data types with a new name. The C typedef keyword is used to redefine the name of already existing data types.

When names of datatypes become difficult to use in programs, typedef is used with user-defined datatypes, which behave similarly to defining an alias for commands.

Similar Reads

C typedef Syntax

typedef existing_name alias_name;...

Example of typedef in C

typedef long long ll;...

Use of typedef in C

...

1. typedef struct

Following are some common uses of the typedef in C programming:...

2. typedef with Pointers

typedef can also be used with structures in the C programming language. A new data type can be created and used to define the structure variable....

3. typedef with Array

...

C typedef vs #define

typedef can also be used with pointers as it gives an alias name to the pointers. Typedef is very efficient while declaring multiple pointers in a single statement because pointers bind to the right on the simple declaration....

FAQs on typedef in C

...