[c++运用]-利用指针查看分配内存及后续连接的内存---ShinePans

来源:互联网 发布:徐老师淘宝店衣服 编辑:程序博客网 时间:2024/05/22 15:13
#include <iostream>#include <windows.h>#include <stdlib.h>#include <conio.h>using namespace std;int main(){char x;tag:cout << "先将进行获取内存,请输入您想获得的类型:" << endl;cout << "1.int\n2.float\n3.double\n4.char\n5.bool\n" << endl;while (1){if (_kbhit()){x = _getch();if (x == '1'){int i = 1;cout << "您选择的是int!(开始时按任意键结束)" << endl;system("pause");int *pi = &i;for (int index = 0; index < 5000; ++index){if (index % 8 == 0)cout << endl;Sleep(20);cout << pi++ << " ";if (_kbhit())  goto tag;}}else if (x == '2'){float f = 0.1;float *pf = &f;cout << "您选择的是float!(开始时按任意键结束)" << endl;system("pause");float *p = &f;for (int index = 0; index < 5000; ++index){if (index % 8 == 0)cout << endl;Sleep(20);cout << pf++ << " ";if (_kbhit())  goto tag;}}else if (x == '3'){double d = 0.01;double *p = &d;cout << "您选择的是double!(开始时按任意键结束)" << endl;system("pause");double *pd = &d;for (int index = 0; index < 5000; ++index){if (index % 8 == 0)cout << endl;Sleep(20);cout << pd++ << " ";if (_kbhit())  goto tag;}}else if (x == '4'){char c = 'c';char *pc = &c;cout << "您选择的是double!(开始时按任意键结束)" << endl;system("pause");for (int index = 0; index < 5000; ++index){if (index % 8 == 0)cout << endl;Sleep(20);cout << pc++ << " ";if (_kbhit())  goto tag;}}else if (x == '5'){bool b = true;bool *pb = &b;cout << "您选择的是bool!(开始时按任意键结束)" << endl;system("pause");for (int index = 0; index < 5000; ++index){if (index % 8 == 0)cout << endl;Sleep(20);cout << pb++ << " ";if (_kbhit())  goto tag;}}}}}


exe:http://yunpan.cn/Q4jKz4VJxAJMz

0 0
原创粉丝点击