typedef with Array

typedef can also be used with an array to increase their count. 

Example:

typedef int arr[20]

Here, arr is an alias for an array of 20 integer elements.

// it's same as Arr[20], two-Arr[20][23];
arr Arr, two-Arr[23]; 

Example 3: Using typedef to define an alias for Array.

C




// C program to implement typedef with array
#include <stdio.h>
 
typedef int Arr[4];
 
// Driver code
int main()
{
    Arr temp = { 10, 20, 30, 40 };
    printf("typedef using an array\n");
 
    for (int i = 0; i < 4; i++) {
        printf("%d ", temp[i]);
    }
    return 0;
}


Output

typedef using an array
10 20 30 40 

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

...