Monday, June 18, 2012

To demonstrate copying of structures


/* Program to demonstrate copying of structures */

#include<stdio.h>

#include<conio.h>

void main()

{

  struct employee

  {

     char name[10];

     int age;

     float salary;

  };

  struct employee e1={"Arnav",28,40000.00};

  struct employee e2,e3;

  clrscr();

  /* Copying one by one */

  strcpy(e2.name,e1.name);

  e2.age=e1.age;

  e2.salary=e1.salary;

  /* Copying all elements at one go */

  e3=e2;

  printf("\n%s\t%d\t%f",e1.name,e1.age,e1.salary);

  printf("\n%s\t%d\t%f",e2.name,e2.age,e2.salary);

  printf("\n%s\t%d\t%f",e3.name,e3.age,e3.salary);

  getch();

}

 

OUTPUT

Arnav   28      40000.000000

Arnav   28      40000.000000

Arnav   28      40000.000000

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.