C++ examples for Data Type:struct
Demonstrates assigning one structure to another.
#include <iostream> using namespace std; #include <iomanip> struct student/* www . jav a2s . co m*/ { char st_name[25]; char grade; int age; float average; }; void main() { student std1 = {"Test", 'A', 13, 91.4}; struct student std2, std3; // Not initialized std2 = std1; // Copies each member of std1 std3 = std1; // to std2 and std3. cout << "The contents of std2:\n"; cout << std2.st_name << " " << std2.grade << " "; cout << std2.age << " " << setprecision(1) << std2.average << "\n\n"; cout << "The contents of std3:\n"; cout << std3.st_name << " " << std3.grade << " "; cout << std3.age << " " << std3.average << "\n"; return; }