ADVERTISEMENT
ADVERTISEMENT

C - Example of TypeDef Struct Structure Name in C Language.


IncludeHelp 12 August 2016

In this code snippet we will learn how we can use typedef structure in c language by using typedef structure? We can define a name to the structure and use it later.

Generally everywhere we need declared structure we use struct structure_name but after declaring it with a typedef we can simply use it by that typedef.

For an example there is a structure struct employee, we will declare it with typedef EMP. In our program we can use EMP instead of struct employee.

C Code Snippet - C Structure TypeDef Example

/*C - Example of TypeDef Struct Structure Name in C Language.*/

#include <stdio.h>

//structure declaration
struct employee{
	char name[100];
	int age;
};

//typedef structure declaration
typedef struct employee EMP;

int main(){
	//declare structure variable
	EMP employee1;
	
	printf("Enter employee's name: ");
	gets(employee1.name);
	
	printf("Enter age: ");
	scanf("%d",&employee1.age);
	
	
	printf("Name: %s\nAge: %d\n",employee1.name,employee1.age);
	
	return 0;	
}
    Enter employee's name: Angel Mie
    Enter age: 21
    Name: Angel Mie
    Age: 21

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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.