Using a Structure in a Program

Now that we’ve covered some of the main features of structures, it’s time to put the ideas together in a structure-using program. Listing 4.11 illustrates these points about a structure. Also it shows how to initialize one.

Listing 4.11. structur.cpp

// structur.cpp -- a simple structure#include <iostream>struct inflatable   // structure declaration{    char name[20];    float volume;    double price;};int main(){    using namespace std;    inflatable guest =    {        "Glorious Gloria",  // name value        1.88,               // volume value        29.99               // price value    };  // guest is a structure variable of type inflatable// It's initialized to the indicated values    inflatable pal =    { ...

Get C++ Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.