Home » C programs » C typedef programs

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.
Submitted by IncludeHelp, on September 06, 2018

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




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.