Thursday 10 November 2016

C Program to demonstrate structure

  1. #include <stdio.h>  
  2. #include <string.h>  
  3. struct employee    
  4. {   int id;    
  5.     char name[50];    
  6. }e1;  //declaring e1 variable for structure  
  7. int main( )  
  8. {  
  9.    //store first employee information  
  10.    e1.id=101;  
  11.    strcpy(e1.name, "Soniya");//copying string into char array  
  12.    //printing first employee information  
  13.    printf( "employee 1 id : %d\n", e1.id);  
  14.    printf( "employee 1 name : %s\n", e1.name);  
  15.    return 0;  
  16. }  
Output:
employee 1 id : 101
employee 1 name : Soniya

No comments:

Post a Comment