第六章 6.2 参数传递
来源:互联网 发布:ipadpro下载软件流程 编辑:程序博客网 时间:2024/06/11 16:53
6.10编写一个函数,使用指针形参交换两个整数的值。在代码中调用该函数并输出交换后的结果。
#include<iostream>using namespace std;void changeAB(int *a, int *b);int main(){ int a = 5,b = 6; cout << "before:" << a << " " << b << endl; changeAB(&a,&b); cout << "after:" << a << " " << b <<endl;}void changeAB(int *a,int *b){ int temp = *a; *a = *b; *b = temp;}
6.17编写一个函数,判断string对象中是否含有大写字母。编写另一个函数,把string对象全部改写成小写形式。
#include<iostream>#include<string>using namespace std;bool is_super(const string s);void change_low(string *s);//void change_low(string &s);int main(){ cout << "请输入字符串:"; string s = ""; cin >> s; cout << is_super(s) <<endl; change_low(&s); cout << s <<endl; return 0;}bool is_super(const string s){ for(auto c : s) { if(isupper(c)) return true; } return false;}void change_low(string *s){ for(auto &c : *s) { if(isupper(c)) { c = tolower(c); } }}/*void change_low(string &s){ for(auto &c : s) { if(isupper(c)) { c = tolower(c); } }}*/
6.18为下面的函数编写函数声明。
(1)bool compare(const &matrix a, const &matrix b);//比较两个matrix类是否相等
(2)vector<int> change_val(int a, *vercto<int> iv);//
6.21编写一个函数,令其接受两个参数:一个是int型的数,一个是int指针。函数比较int的值和指针所指的值,返回较大的那个。
#include<iostream>using namespace std;int print(const int, const int*);int main(){ int a = 7, b[] = {1,2}; int c = print(a,b); cout << c << endl;}int print(const int a, const int* b){ return a > *b ? a : *b;}
6.22编写一个函数,令其交换两个int指针。
#include<iostream>using namespace std;void swap(int*&, int*&);int main(){ int a = 7, b = 8; int *p = &a,*q = &b; cout << *p << " " << *q << endl; swap(p,q); cout << *p << " " << *q << endl; cout << a << " " << b << endl;}void swap(int*& a, int*& b){ int* temp = a; a = b; b = temp;}
6.25编写一个main函数,令其接受两个实参,把实参内容连接成一个string对象并输出出来。
#include<iostream>#include<string>using namespace std;int main(int argc, char *argv[]){ string a = argv[1]; cout << a << endl; string b = argv[2]; cout << b << endl; cout << a + b << endl;}
0 0
- 第六章 6.2 参数传递
- 编程学习第六天,参数传递
- 《C++ Primer》读书笔记第六章-1-函数基础 And 参数传递
- 参数传递
- 参数传递
- 参数传递
- 传递参数
- 参数传递
- 参数传递
- 参数传递
- 传递参数
- 参数传递
- 参数传递
- 参数传递
- 参数传递
- *参数传递*
- 参数传递
- 参数传递
- Caffe入门(1)——Ubuntu 16.04 caffe无GPU模式安装
- ARM Linux系统下如何修改动态IP为静态IP地址
- Windows线程异常捕捉
- 【Light-oj】-1282 - Leading and Trailing(数论,快速幂,log,好)
- django执行原生sql
- 第六章 6.2 参数传递
- 关于LeetCode中Maximum Depth of Binary Tree一题的理解
- mysql的初次接触
- Light OJ:1045 Digits of Factorial(数学+思维+对数)
- jdbc事务和事务的隔离级别
- nginx访问报错403 is forbidden
- 组合模式(java版)
- Redis 单机/集群离线安装部署
- 嵌入式复习2