- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
struct.cpp
using namespace std;
struct inflatable
{
string name;
int age;
float weight;
};
struct new_struct
{
string name;
int age;
string addr;
} meowrain = {
"meowrain",
18,
"China"},
linus = {"linux", 40, "America"};
struct {
int x;
int y;
int sum(int x,int y) {
return x+y;
}
}sum;
int main(void)
{
inflatable duck;
duck.name = "mike";
duck.age = 5;
duck.weight = 1.5;
inflatable chicken = {
"john",
6,
1.3};
inflatable dog{"mi", 3, 4};
inflatable cat;
cat = dog;
cout << chicken.age << endl;
cout << dog.name << endl;
cout << cat.name << endl;
cout << meowrain.addr << endl;
cout << linus.addr << endl;
sum.x = 10;
sum.y = 10;
int m = sum.sum(sum.x,sum.y);
cout << m << endl;
}
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
StructArray.cpp
using namespace std;
struct inflatable
{
string name;
int age;
float weight;
};
struct new_struct
{
string name;
int age;
string addr;
} meowrain = {
"meowrain",
18,
"China"},
linus = {"linux", 40, "America"};
struct {
int x;
int y;
int sum(int x,int y) {
return x+y;
}
}sum;
int main(void)
{
inflatable duck;
duck.name = "mike";
duck.age = 5;
duck.weight = 1.5;
inflatable chicken = {
"john",
6,
1.3};
inflatable dog{"mi", 3, 4};
inflatable cat;
cat = dog;
cout << chicken.age << endl;
cout << dog.name << endl;
cout << cat.name << endl;
cout << meowrain.addr << endl;
cout << linus.addr << endl;
sum.x = 10;
sum.y = 10;
int m = sum.sum(sum.x,sum.y);
cout << m << endl;
}