Struct

Programming

This program demonstrates structures (struct), which are similar to classes but with public access by default. They are commonly used for grouping related data.

Implementation

#include <iostream>

struct Point {
    int x, y;
};

int main() {
    Point p1 = {3, 4};
    std::cout << "Point coordinates: (" << p1.x << ", " << p1.y << ")" << std::endl;
    return 0;
}

Key Concepts

Struct vs Class

The main difference between struct and class is the default access level:

Output

Point coordinates: (3, 4)