#include<iostream>usingnamespace std;intmain(){
int a =10;constint*p =&a;constint ca =30;int*q;
cout <<"a的地址为:\t"<<&a <<"\ta的值为:\t"<< a << endl;
cout <<"*p指向的地址为:"<< p <<"\t*p的值为:\t"<<*p << endl;
q =const_cast<int*>(p);*q =20;
cout <<"a的地址为:\t"<<&a <<"\ta的值为:\t"<< a << endl;
cout <<"*p指向的地址为:"<< p <<"\t*p的值为:\t"<<*p << endl;
cout <<"*q指向的地址为:"<< q <<"\t*q的值为:\t"<<*q << endl;
cout <<"分界线"<< endl;
p =&ca;
q =const_cast<int*>(p);*q =40;
cout <<"ca的地址为:\t"<<&ca <<"\tca的值为:\t"<< ca << endl;
cout <<"*p指向的地址为:"<< p <<"\t*p的值为:\t"<<*p << endl;
cout <<"*q指向的地址为:"<< q <<"\t*q的值为:\t"<<*q << endl;return0;}
Practice the default values of function parameters
#include<iostream>usingnamespace std;voidfunc(int a =11,int b =22,int c =33){
cout <<"a="<< a <<",b="<< b <<",c="<< c << endl;}intmain(){
func();//调用是缺少了3个实参,将使用定义中的3个参数默认值func(55);//调用是缺少了后两个实参,将使用定义中的后两个参数默认值func(77,99);//调用时缺少了最后1个实参,将使用定义中的最后1个参数默认值func(8,88,888);//调用时实参完备,将不使用定义中的任何参数默认值return0;}//C++ 语言规定,提供默认值时必须按从右到左的顺序提供,即有默认值的形参必须在形参列表的最后。//如果有某个形参没有默认值,则它左侧的所有形参都不能有默认值voiddefaultvalue(int=2,double=3.0);voiddefaultcalue2(int a,double b =3.0);voiddefalutvalue3(int a =2,double b);//报错voidfunc1(int a,int b =2,int c =3);voidfunc2(int a =1,int b,int c =3);//报错voidfunc3(int a =1,int b =2,int c);//报错