C++ Structures (struct)

🟡 Intermediate

📖 Definition

In C++, a struct is identical to a class except that its members default to public access. It is primarily used for Plain Old Data (POD) aggregates.

💡 Code Example

#include <iostream>
#include <string>

struct Player {
    std::string name;
    int health{100};
};

int main() {
    Player p1{"Hero", 150}; // Aggregate initialization
    std::cout << "Player: " << p1.name << ", HP: " << p1.health << "\n";
    return 0;
}