We can assign of a structure variable to another structure variable , if both variable are defined of the same structure type.
Example::
struct student {
char name[20];
int rollno;
float marks;
};
main()
{
struct student stu1 = {"Perry",25,20};
struct student stu2;
stu2 = stu1;
printf("Stu1 :: %s %d %f\n",stu1.name,stu1.rollno,stu1.marks};
printf("Stu2:: %s %d %f\n",stu2.name,stu2.rollno,stu2.marks};
}
OutPut::
Stu1:: Perry 25 20
Stu2:: Perry 25 20
No comments:
Post a Comment