*64位编译器
char :1个字节
char*(即指针变量): 8个字节
short int : 2个字节
int: 4个字节
unsigned int : 4个字节
float: 4个字节
double: 8个字节
long: 8个字节
long long: 8个字节*/
#include <iostream>
using namespace std;
class Cstu
{
public:
int a[4];
struct MyStruct
{
int i;
char w;
};
MyStruct st;
Cstu(MyStruct s2) : st(s2)//Cstu() : a()这种写法可以实现但是是不正确的写法
{
/*for(int i=0; i < 4; i++ )
{
a[i]=0;
}这是一种正确的写法,但是麻烦*/
memset(a,0,sizeof(a));
/*第一个值是首地址【数组的首地址可以写成a,也可以写成&a[0]
(0元素的地址就是数组的首地址)】、第二个值是设定的值、第三个值是设定的字节数*/
}
void func()
{
for(int i=0; i<4; i++)
{
cout << a[i] << endl;
}
cout << st.i << ' ' << st.w << endl;
}
};
int main()
{
Cstu::MyStruct s1 = {12,'J'};
Cstu stu(s1);
stu.func();
/*Cstu::MyStruct s1 = {12,'D'};
Cstu::MyStruct s2 = s1;说明结构体可以直接赋值
cout << s2.i << ' ' << s2.w << endl;*/
system("pause");
return 0;
}
char :1个字节
char*(即指针变量): 8个字节
short int : 2个字节
int: 4个字节
unsigned int : 4个字节
float: 4个字节
double: 8个字节
long: 8个字节
long long: 8个字节*/
#include <iostream>
using namespace std;
class Cstu
{
public:
int a[4];
struct MyStruct
{
int i;
char w;
};
MyStruct st;
Cstu(MyStruct s2) : st(s2)//Cstu() : a()这种写法可以实现但是是不正确的写法
{
/*for(int i=0; i < 4; i++ )
{
a[i]=0;
}这是一种正确的写法,但是麻烦*/
memset(a,0,sizeof(a));
/*第一个值是首地址【数组的首地址可以写成a,也可以写成&a[0]
(0元素的地址就是数组的首地址)】、第二个值是设定的值、第三个值是设定的字节数*/
}
void func()
{
for(int i=0; i<4; i++)
{
cout << a[i] << endl;
}
cout << st.i << ' ' << st.w << endl;
}
};
int main()
{
Cstu::MyStruct s1 = {12,'J'};
Cstu stu(s1);
stu.func();
/*Cstu::MyStruct s1 = {12,'D'};
Cstu::MyStruct s2 = s1;说明结构体可以直接赋值
cout << s2.i << ' ' << s2.w << endl;*/
system("pause");
return 0;
}