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



Comments and Discussions!

Load comments ↻





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