Aggregate Operations with Structures

Unlike arrays, which prohibit most aggregate operations, it is possible in some cases to manipulate structures as a whole.
   Operation                 Arrays              Structures
Arithmetic               No                     No
Assignment               No                     Yes
Comparison               No                     No
Input/Output(cin/cout)   No (except strings)    No
Parameter passing        By reference only      By reference or value
Return from function     No                     Yes
Notice that you can assign one structure to another.
Employee clerk1, clerk2;    

strcpy(clerk1.firstName, "Ian");
strcpy(clerk1.lastName, "Faith");
clerk1.middleInitial = 'Q';      
clerk1.salary = 45200.50f;       
clerk1.age = 31;                 
clerk1.years = 7;                

clerk2 = clerk1;   // copies all members from clerk1
After the assignment, the corresponding members from clerk1 and clerk2 have the same value (e.g. clerk1.age has the same value as clerk2.age)

Previous page
Next page

Back to Lesson 14 Index
Back to Outline