Use typedef to create new type based on struct - C Structure

C examples for Structure:Structure Definition

Introduction

typedef keyword can create an alias for the structure.

Demo Code

#include <stdio.h> 
#include <string.h> 
typedef struct employee {  //modification here 
   char fname[10]; 
   char lname[10]; 
   int id; /*w ww .  j  a va 2s.  com*/
   float salary; 
} emp;  //modification here 

int main() 
{ 
   emp emp1; 

   strcpy(emp1.fname, "Jack"); 
   strcpy(emp1.lname, "Smith");  
   emp1.id = 123; 
   emp1.salary = 50000.00; 

   printf("\nFirst Name: %s\n", emp1.fname); 
   printf("Last Name: %s\n", emp1.lname); 
   printf("Employee ID: %d\n", emp1.id); 
   printf("Salary: $%.2f\n", emp1.salary); 
}

Result


Related Tutorials