<<< | Index | C++ struct >>> |
In C, the structures are introduced by the struct keyword.
The struct aggeregates data members into a single object.
The struct can be used as a user-defined data type:
#include <iostream> struct Rectangle { int width; // member variable int height; // member variable }; int main() { Rectangle rect { 20, 10 }; std::cout << "rectangle width: " << rect.width << '\n'; std::cout << "rectangle height: " << rect.height << '\n'; return 0; }
In this sample, the rect is an object. This object is the result of instantiation of the struct Rectangle.
<<< | Index | C++ struct >>> |