#include <iostream>
#include <vector>
#include <map>
#include <Windows.h>
// BYTE=unsigned char
// WORD=unsigned short
// DWORD=unsigned long
using namespace std;
void main()
{
int i;
double a;
float b;
WORD e;
DWORD c;
vector<int> pvector;
vector<DWORD> Dvector;
map<DWORD,DWORD> DMap;
map<int,int>iMap;
cout<<"32位系统的各个类型的字节数"<<endl;
cout<<"int类型:"<<sizeof(i)<<endl;
cout<<"double类型:"<<sizeof(a)<<endl;
cout<<"float类型:"<<sizeof(b)<<endl;
cout<<"WORD类型:"<<sizeof(e)<<endl;
cout<<"DWORD类型:"<<sizeof(c)<<endl;
cout<<"vector<int> pvector类型:"<<sizeof(pvector)<<endl;
pvector.resize(100);
cout<<"执行pvector.resize(100)后,vector<int> pvector类型:"<<sizeof(pvector)<<endl;
cout<<"vector<DWORD> Dvector类型:"<<sizeof(Dvector)<<endl;
cout<<"map<DWORD,DWORD>类型:"<<sizeof(map<DWORD,DWORD>)<<endl;
cout<<"map<DWORD,DWORD> DMap类型:"<<sizeof(DMap)<<endl;
cout<<"map<int,int>类型:"<<sizeof(iMap)<<endl;
system("pause");
//return 0;
}
运行结果:
2\
/*
******************************************************************
* 一元操作符与二元操作符
* 当一元运算符被定义为成员函数时,没有参数,成员函数会被运算符右侧的对象调用;
* 当二元运算符被定义为成员函数时,只含有一个参数,成员函数会被运算符左侧的对象调用。
* C++标准中有这样详细的阐述:
* A binary operator shall be implemented either by a non-static member function with
* one parameter or by a non-member function with two parameters
******************************************************************
*/
#include <iostream>
using namespace std;
class A
{
private:
int a;
public:
A(){a = 0;}
void operator++()
{
a+=1;
}
void operator++(int)
{
a += 2;
}
friend void print(const A &c);
};
void print(const A &c)
{
cout<<c.a<<endl;
}
void main()
{
A classa;
print(classa);
++classa;//调用一元操作
print(classa);
classa++;//调用二元操作
print(classa);
system("pause");
}
运行结果:
3\
#include <stdio.h>
int main()
{
double a =8;
float b = 2;
printf("%d\n",5.01);//输出结果会让你大吃一惊,是一个大数字
printf("%f\n",5);//更不可思议,在printf函数里,float会自动转换成double。因此4字节(32位平台)的int类型的值会被当成8个字节的double型来读取。
//结果可想而知,内存访问越界,程序运行结果是0.000000(小数点后面跟了6个0)
printf("%lf\n",a);
printf("%f\n",b);//%lf,%f都是按照double类型的数字来输出。
return 0;
}