Example by: Ira Oldham, References: Savitch eighth edition, section 10.1; Gaddis seventh edition, section 10.4
The member variables within a structure variable can be initialized when the structure variable is defined.
1 struct Part
2 {
3 int id;
4 int onHand;
5 double cost;
6 };
7 int main(void)
8 {
9 Part wrench = {12345, 13, 8.10};
10 cout << "ID: " << wrench.id << endl;
11 cout << "On Hand: " << wrench.onHand << endl;
12 cout << "Cost: " << wrench.cost << endl;
13 return 0;
14 }
ID: 12345 On Hand: 13 Cost: 8.10
The list of initial values are enclosed in braces and seperated with commas. The order of thie initialization list is the same as the order of the definition of the member variables.