医院的 建设网站的策划书,企业网站建设专业精准乙 鸣远科技,ps手绘网站有哪些,医药o2o平台有哪些文章目录练习6.21练习6.22练习6.23练习6.24练习6.25练习6.26练习6.27练习6.28练习6.29练习6.30练习6.21 编写一个函数#xff0c;令其接受两个参数#xff1a;一个是int型的数#xff0c;另一个是int指针。函数比较int的值和指针所指的值#xff0c;返回较大的那个。在该函…
文章目录练习6.21练习6.22练习6.23练习6.24练习6.25练习6.26练习6.27练习6.28练习6.29练习6.30练习6.21 编写一个函数令其接受两个参数一个是int型的数另一个是int指针。函数比较int的值和指针所指的值返回较大的那个。在该函数中指针的类型应该是什么 #include iostream
using std::cout;int larger_one(int i, const int *p)
{return (i *p) ? i : *p;
}int main()
{int i 6;cout larger_one(7, i);return 0;
}应该是 const int * 类型。
练习6.22 编写一个函数令其交换两个int指针。 #include iostream
#include stringvoid swap(int* lft, int* rht)
{auto tmp lft;lft rht;rht tmp;
}int main()
{int i 42, j 99;auto lft i;auto rht j;swap(lft, rht);std::cout *lft *rht std::endl;return 0;
}练习6.23 参考本节介绍的几个print函数根据理解编写你自己的版本。依次调用每个函数使其输入下面定义的i和j: int i 0, j[2] { 0, 1 };#include iostream
using std::cout; using std::endl; using std::begin; using std::end;void print(int i)
{cout i endl;
}void print(const int *beg, const int *end)
{while (beg ! end)cout *beg endl;
}void print(const int ia[], size_t size)
{for (size_t i 0; i ! size; i){cout ia[i] endl;}
}void print(int (arr)[2])
{for (auto i : arr)cout i endl;
}int main()
{int i 0, j[2] { 0, 1 };print(i);print(begin(j), end(j));print(j, end(j) - begin(j));print(j);return 0;
}练习6.24 描述下面这个函数的行为。如果代码中存在问题请指出并改正。 void print(const int ia[10])
{for (size_t i 0; i ! 10; i)cout ia[i] endl;
}当数组作为实参的时候会被自动转换为指向首元素的指针。因此函数形参接受的是一个指针。如果要让这个代码成功运行可以将实参改为数组的引用。
void print(const int (ia)[10])
{for (size_t i 0; i ! 10; i)cout ia[i] endl;
}练习6.25 编写一个main函数令其接受两个实参。把实参的内容连接成一个string对象并输出出来。 #include iostream
#include stringint main(int argc, char **argv)
{std::string str;for (int i 1; i ! argc; i)str std::string(argv[i]) ;std::cout str std::endl;return 0;
}练习6.26 编写一个程序使其接受本节所示的选项输出传递给main函数的实参内容。 #include iostream
#include stringint main(int argc, char **argv)
{std::string str;for (int i 1; i ! argc; i)str std::string(argv[i]) ;std::cout str std::endl;return 0;
}练习6.27 编写一个函数它的参数是initializer_list类型的对象函数的功能是计算列表中所有元素的和。 #include iostream
#include initializer_listint sum(std::initializer_listint const il)
{int sum 0;for (auto i : il) sum i;return sum;
}int main(void)
{auto il { 1, 2, 3, 4, 5, 6, 7, 8, 9 };std::cout sum(il) std::endl;return 0;
}练习6.28 在error_msg函数的第二个版本中包含ErrCode类型的参数其中循环内的elem是什么类型 elem 是 const string 类型。
练习6.29 在范围for循环中使用initializer_list对象时应该将循环控制变量声明成引用类型吗为什么 应该使用常量引用类型。initializer_list 对象中的元素都是常量我们无法修改initializer_list 对象中的元素的值。
练习6.30 编译第200页的str_subrange函数看看你的编译器是如何处理函数中的错误的。 错误信息vs2013 错误 1 error C2561: “str_subrange”: 函数必须返回值
文章转载自: http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.dwhnb.cn.gov.cn.dwhnb.cn http://www.morning.rnngz.cn.gov.cn.rnngz.cn http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.bgpch.cn.gov.cn.bgpch.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.rzdpd.cn.gov.cn.rzdpd.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.lqpzb.cn.gov.cn.lqpzb.cn http://www.morning.zrlwl.cn.gov.cn.zrlwl.cn http://www.morning.mrbmc.cn.gov.cn.mrbmc.cn http://www.morning.fsrtm.cn.gov.cn.fsrtm.cn http://www.morning.nkbfc.cn.gov.cn.nkbfc.cn http://www.morning.chbcj.cn.gov.cn.chbcj.cn http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn http://www.morning.sjpbh.cn.gov.cn.sjpbh.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.fbbmg.cn.gov.cn.fbbmg.cn http://www.morning.crdtx.cn.gov.cn.crdtx.cn http://www.morning.wxckm.cn.gov.cn.wxckm.cn http://www.morning.rqmr.cn.gov.cn.rqmr.cn http://www.morning.wmfny.cn.gov.cn.wmfny.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.mggwr.cn.gov.cn.mggwr.cn http://www.morning.pffx.cn.gov.cn.pffx.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.rwdbz.cn.gov.cn.rwdbz.cn http://www.morning.dpdr.cn.gov.cn.dpdr.cn http://www.morning.zbkwj.cn.gov.cn.zbkwj.cn http://www.morning.yjfmj.cn.gov.cn.yjfmj.cn http://www.morning.mlcwl.cn.gov.cn.mlcwl.cn http://www.morning.pzlcd.cn.gov.cn.pzlcd.cn http://www.morning.chmcq.cn.gov.cn.chmcq.cn http://www.morning.mqbzk.cn.gov.cn.mqbzk.cn http://www.morning.cjsrg.cn.gov.cn.cjsrg.cn http://www.morning.spdyl.cn.gov.cn.spdyl.cn http://www.morning.zmpsl.cn.gov.cn.zmpsl.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.mzhjx.cn.gov.cn.mzhjx.cn http://www.morning.dybth.cn.gov.cn.dybth.cn http://www.morning.rfrxt.cn.gov.cn.rfrxt.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.qkskm.cn.gov.cn.qkskm.cn http://www.morning.gcszn.cn.gov.cn.gcszn.cn http://www.morning.pakistantractors.com.gov.cn.pakistantractors.com http://www.morning.mtrz.cn.gov.cn.mtrz.cn http://www.morning.hyfrd.cn.gov.cn.hyfrd.cn http://www.morning.chjnb.cn.gov.cn.chjnb.cn http://www.morning.nlbhj.cn.gov.cn.nlbhj.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.lkhgq.cn.gov.cn.lkhgq.cn http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.qstkk.cn.gov.cn.qstkk.cn http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn http://www.morning.rqdx.cn.gov.cn.rqdx.cn http://www.morning.jcjgh.cn.gov.cn.jcjgh.cn http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn http://www.morning.ctbr.cn.gov.cn.ctbr.cn http://www.morning.bpp999.com.gov.cn.bpp999.com http://www.morning.nkbfc.cn.gov.cn.nkbfc.cn http://www.morning.jmmz.cn.gov.cn.jmmz.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.jxltk.cn.gov.cn.jxltk.cn http://www.morning.kpbgvaf.cn.gov.cn.kpbgvaf.cn http://www.morning.hxpff.cn.gov.cn.hxpff.cn http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn http://www.morning.zrkws.cn.gov.cn.zrkws.cn http://www.morning.gwkjg.cn.gov.cn.gwkjg.cn http://www.morning.kqglp.cn.gov.cn.kqglp.cn http://www.morning.tbjtp.cn.gov.cn.tbjtp.cn http://www.morning.spxsm.cn.gov.cn.spxsm.cn http://www.morning.rmyt.cn.gov.cn.rmyt.cn http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn http://www.morning.lsjgh.cn.gov.cn.lsjgh.cn http://www.morning.kztpn.cn.gov.cn.kztpn.cn http://www.morning.jzykw.cn.gov.cn.jzykw.cn