๐๏ธStructure
Collection of different data types
struct Point { int x; int y; };Point p1; p1.x = 10; p1.y = 20; // Or using an initializer list (C++11 and later) Point p2 = {30, 40};std::cout << "p1: (" << p1.x << ", " << p1.y << ")" << std::endl;struct Rectangle { int width; int height; int area() { return width * height; } };struct Person { std::string name; int age; Person(std::string n, int a) : name(n), age(a) {} }; Person alice("Alice", 30);struct Address { std::string street; std::string city; }; struct Employee { std::string name; Address workAddress; };Point* pPtr = &p1; std::cout << pPtr->x << ", " << pPtr->y << std::endl;
Last updated