//应用枚举类型
#i nclude <iostream>
#i nclude <string>
using namespace std;
enum InstanceState{CLOSE = 1, OPEN,MOUNT = 4, UNMOUNT}; //定义数据库的状态
void OracleOpt(InstanceState state)
{
switch(state)
{
case CLOSE:
{
cout<<"关闭数据库"<<endl;
break;
}
case OPEN:
{
cout<<"打开数据库"<<endl;
break;
}
case MOUNT:
{
cout<<"挂起数据库"<<endl;
break;
}
case UNMOUNT:
{
cout<<"卸载数据库"<<endl;
break;
}
default:
break;
}
}
void main()
{
InstanceState state = OPEN;
OracleOpt(state);
//OracleOpt(0); //错误,不能把整型转为枚举型
}
=========
//结构体类型
#i nclude <iostream>
#i nclude <string>
using namespace std;
const int MAX_CHAR=128;
struct Student
{
char name[MAX_CHAR];
char sex[MAX_CHAR];
unsigned int age;
char addr[MAX_CHAR];
}stdnt;
void main()
{
Student stdnt;
stdnt.age = 10;
cout<<stdnt.age<<endl;
}
===========
//结构体类型
#i nclude <iostream>
#i nclude <string>
using namespace std;
const int MAX_CHAR=128;
struct Student
{
char name[MAX_CHAR];
char sex[MAX_CHAR];
unsigned int age;
char addr[MAX_CHAR];
}stdnt;
void main()
{
Student stdnt;
stdnt.age = 10;
Student another;
another=stdnt; //结构体变量之间的复制
cout<<stdnt.age<<endl;
cout<<another.age<<endl;
}
=====
//指针类型
#i nclude <iostream>
#i nclude <string>
using namespace std;
void main()
{
int ivar=10;
int *pvar=&ivar; //这里的pvar是地址,*pvar是指针,指向pvar的地址,&ivar是取地址。
*pvar=8;
cout<<ivar<<endl; //值
cout<<*pvar<<endl; //指针指向的值
cout<<pvar<<endl; //指针指向的地址
cout<<&ivar<<endl; //取地址
}
===========
//使用指针变量输出数组元素
#i nclude <iostream>
#i nclude <string>
using namespace std;
void main()
{
int iarray[5] = {1,2,3,4,5}; //定义数组并初始化
int* pvar = iarray; //定义指针变量指向数组首地址
for(int i=0;i<5;i++) //注意不要越界,越界并不报错的
{
cout<<"数据元素:"<<i<<"值"<<*pvar<<endl;
pvar = pvar + 1; //移动指针,指向下一个元素
}
}
==========