Thursday, September 30, 2010

Structure Assignments in C,C++

The information contained in one structure may be assigned to another structure of the
same type using a single assignment statement. That is, you do not need to assign the
value of each member separately. The following program illustrates structure
assignments:
#include <stdio.h>
int main(void)
 {
struct {
int a;
int b;
} x, y;
x.a = 10;
y = x; /* assign one structure to another */
printf("%d", y.a);
return 0;
}
After the assignment, y.a will contain the value 10.

No comments:

Post a Comment