Example of typedef in C language

Here, we will learn how to use typedef to provide name to a data type? Here, we are defining name for an int, a char and a float.
By IncludeHelp Last updated : March 10, 2024

What is typedef?

typedef is a keyword in C programming language, it is used to define a name to the data type, for example, if you want to define "I" for an int variable, or "UC" for unsigned char etc.

Syntax

 typedef name datatype_name;

Example

#include <stdio.h>

typedef int I;
typedef char C;
typedef float F;

int main()
{
	I intVar = 10;
	C charVar = 'X';
	F floatVar = 10.23f;
	
	printf("intVar = %d\n",intVar);
	printf("charVar = %c\n",charVar);
	printf("floatVar = %f\n",floatVar);
	
	return 0;
}

Output

intVar = 10
charVar = X
floatVar = 10.230000

C typedef Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.