cpp 4.22
来源:互联网 发布:android数独游戏源码 编辑:程序博客网 时间:2024/05/16 10:00
4.22
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<cstring>using namespace std;char * getname(void);int main(){char * name;name = getname();cout << name << " at " << (int *)name << "\n";delete [] name;name = getname();cout << name << " at " << (int *)name << "\n";delete[] name;return 0;}char*getname(){char temp[80];cout << "Enter last name: ";cin >> temp;char*pn = new char[strlen(temp) + 1];strcpy(pn, temp);return pn;}
4.23
#include<iostream>struct antarctica_years_end{int year;};int main(){antarctica_years_end s01, s02, s03;s01.year = 1998;antarctica_years_end*pa = &s02;pa->year = 1999;antarctica_years_end trio[3];trio[0].year = 2003;std::cout << trio->year << std::endl;const antarctica_years_end*arp[3] = {&s01, &s02, &s03};std::cout << arp[1]->year << std::endl;const antarctica_years_end**ppa = arp;auto ppb = arp;std::cout << (*ppa)->year << std::endl;std::cout << (*(ppb+1))->year << std::endl;system("pause");return 0;}
4.24
#include<iostream>#include<vector>#include<array>int main(){using namespace std;double a1[4] = {1.2, 2.4, 3.6, 4.8};vector<double> a2(4);a2[0] = 1.0 / 3.0;a2[1] = 1.0 / 5.0;a2[2] = 1.0 / 7.0;a2[3] = 1.0 / 9.0;array<double, 4> a3 = { 3.14, 2.72, 1.62, 1.41 };array<double, 4> a4;a4 = a3;cout << "a1[2]: " << a1[2] << " at " << &a1[2] << endl;cout << "a2[2]: " << a2[2] << " at " << &a2[2] << endl;cout << "a3[2]: " << a3[2] << " at " << &a3[2] << endl;cout << "a4[2]: " << a4[2] << " at " << &a4[2] << endl;a1[-2] = 20.2;cout << "a1[-2]: " << a1[-2] << " at " << &a1[-2] << endl;cout << "a3[2]: " << a3[2] << " at " << &a3[2] << endl;cout << "a4[2]: " << a4[2] << " at " << &a4[2] << endl;return 0;}
a3[2]和a1[-2]值和地址并不相同,与书中不一致,原因不知道
0 0
- cpp 4.22
- Sample 4.22:delete.cpp
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- ClientSockThread.cpp&&ClientUrlThread.cpp
- cpp调用其他cpp
- ex34a.cpp&&ex34aDoc.cpp&&ex34aView.cpp
- MainFrm.cpp&&ServerThread.cpp&&SheetConfig.cpp
- 《C++ Primer Plus》第五版 程序清单4.22 delete.cpp
- CPP thread
- cpp->html
- CFaderWnd.cpp
- PasswordReminder.cpp
- java 签名
- 自定义View笔记
- 正则表达式
- Django(Session,Cookie)
- bootstrap学习总结-css组件(三)
- cpp 4.22
- Android官方MVP架构示例项目解析
- 欢迎使用CSDN-markdown编辑器
- java学习过程中乱记的笔记
- C++动态链接库导出函数或者类
- Android应用 手势密码的实现(二)
- 一个2年Android开发者的18条建议
- WebApi2中action几种返回值
- 模态窗口小结