c++ primer 练习 3.37、3.38、3.39、3.40
来源:互联网 发布:流畅的电视直播软件 编辑:程序博客网 时间:2024/05/24 02:03
3.37
#include<iostream>using std::cout;using std::cin;using std::endl;int main(){ const char ca[] = {'h', 'e', 'l', 'l', 'o'}; const char *cp = ca; while (*cp) { cout << *cp << endl; ++cp; } return 0;}out:
helloa
3.38
纯属搬运
Pointer addition is forbidden in C++, you can only subtract two pointers.The reason for this is that subtracting two pointers gives a logically explainable result - the offset in memory between two pointers. Similarly, you can subtract or add an integral number to/from a pointer, which means "move the pointer up or down". Adding a pointer to a pointer is something which is hard to explain. What would the resulting pointner represent?If by any chance you explicitly need a pointer to a place in memory whose address is the sum of some other two addresses, you can cast the two pointers to int, add ints, and cast back to a pointer. Remember though, that this solution needs huge care about the pointer arithmetic and is something you really should never do.
3.39
1
#include<iostream>using std::cout;using std::cin;using std::endl;#include<cstring>int main(){ const char ca1[] = "string-A"; const char ca2[] = "string-B"; if (strcmp(ca1 , ca2) > 0) { cout << "string-A big" << endl; } else { cout << "string-B big" << endl; } return 0;}
2
#include<iostream>using std::cout;using std::cin;using std::endl;#include<string>using std::string;int main(){ string s1 = "string-A"; string s2 = "string-B"; cout << "Big one is: "; if (s1 > s2) { cout << s1 << endl; } else { cout << s2 << endl; } return 0;}
#include<cstring>#include<iostream>using std::cout;using std::cin;using std::endl;int main(){ char s1[100] = "stringA"; char s2[] = "stringB"; strcat(s1 , s2); char s[100]; strcpy(s , s1); cout << s << endl; return 0;}
1 0
- c++ primer 练习 3.37、3.38、3.39、3.40
- C++Primer 练习 12.7
- c++primer练习10.9
- c++primer练习10.11
- c++primer练习10.13
- c++primer练习10.14
- c++primer练习10.15
- c++primer练习10.18
- c++primer 练习11.9
- c++primer练习11.33
- c++Primer 练习2.41
- C++Primer中文版中的练习
- C++primer 文本查询练习
- C++Primer练习3.13疑问?
- c primer 8.1练习答案
- C++Primer 练习9.44 解答
- c primer plus13章练习
- 【C++】primer plus 练习7.1
- 嵌入式应用层开发学习步骤
- Python取模运算
- caffe windows cpu matlab python安装
- 用DNSmasq搭建小型的内网DNS
- 01背包(Bone Collector)
- c++ primer 练习 3.37、3.38、3.39、3.40
- 利用artisan新建表及填充数据
- Vue入门系列之Vue实例详解与生命周期
- 怎样判断服务器的端口是否打开-------telnet ip port
- Spring定时器corn表达式详解
- android studio 代码混淆
- 【个人笔记重点,不作为参考】主题:承诺与异步编程
- React Native源码中JavaScriptCore详解
- hdu2084 数塔