Back To C++ Structures
nested structure means structure within a structure
//program to create a structure complex number with members(real and imaginary), creates two structure variables and passes these variables to function which calculates sum of two complex number structure variables into a new structure variable and returns the variable #include
#include
struct complex { int real; int imaginary; }; complex add(complex a,complex b) { complex c; c.real=a.real+b.real; c.imaginary=a.imaginary+b.imaginary; return c; } void main() { complex a,b,sum; clrscr(); cout<<"\nenter real part of complex number 1 : "; cin>>a.real; cout<<"\nenter imaginary part of complex number 1 :"; cin>>a.imaginary; cout<<"complex number 1 is "<
>b.real; cout<<"\nenter imaginary part of complex number 2 : "; cin>>b.imaginary; cout<<"complex number 2 is "<