구조체
#include <iostream>
using namespace std;
int main() {
string name;
string position;
float height;
float weight;
struct MyStruct
{
string name;
string position;
float height;
int weight;
}B;
MyStruct A;
A.name = "son";
A.position = "Striker";
A.height = 183.0;
A.weight = 88;
B = {
};
cout << B.height << endl;
MyStruct C[2] = {
{"A", "A", 1, 1},
{"B", "B", 2, 2}
};
cout << C[0].height << endl;
return 0;
}
공용체(union) 열거체 (enum)
#include <iostream>
using namespace std;
int main() {
union MyUnion
{
int intVal;
long longVal;
float floatVal;
};
MyUnion test;
test.intVal= 3;
cout << test.intVal << endl;
test.longVal = 33;
cout << test.intVal << endl;
cout << test.longVal<< endl;
test.floatVal = 3.3;
cout << test.intVal << endl;
cout << test.floatVal << endl;
cout << test.floatVal << endl;
enum spectrum {red,orange,yellow, green, blue, violet, indigo, ultraviolet
};
enum spectrum {
red= 0 , orange = 2, yellow = 4, green, blue, violet, indigo, ultraviolet
};
spectrum a = orange;
int b;
b = blue;
b = blue + 3;
cout << a << endl;
}