Example for printing structure values in c:
What is the output of below c program?
} s1, s2;
s1.cname = malloc(100);
s1.cno = 1;
strcpy(s1.cname, "skill gun");
s2 = s1;
printf("%d %s ", s2.cno, s2.cname);
it prints "skill gun", 1
it prints 1, "skill gun".
it gives error saying "incompatible types when assigning" at line s2 = s1;
it crashes at run time.
we can use assignment operator to assign values of one variable of a structure to another variable of same structure, it will copy them properly. so it prints 1, "skill gun".
Back To Top