-
有默认参数值的参数必须在参数表的最右端查看全部
-
引用作函数参数查看全部
-
引用可理解为别名查看全部
-
函数参数默认值查看全部
-
发烦烦烦烦烦烦烦查看全部
-
内存的申请与释放 也就是new 与delete查看全部
-
代码演示查看全部
-
C语言与C++ 不同查看全部
-
引用作函数参数查看全部
-
指针类型的引用查看全部
-
#include <iostream> #include<stdio.h> using namespace std; int main(void) { int *p=new int [1000]; if(p==NULL) { system("pause"); return 0; } p[0]=10; p[1]=20; cout<<p[0]<<","<<p[1]<<endl; delete []p;//如果是delete则只删除p[0]; p=NULL; system("pause"); return 0; } /* #include <iostream> #include<stdio.h> using namespace std; int main(void) { int *p=new int (10); cout<<*p<<endl; delete p; p=NULL; system("pause"); return 0; }查看全部
-
#include <iostream> #include <stdio.h> using namespace std; inline void fun (double i=1.1,double j=2.2); inline void fun (int i=30,int j=20,int k=10); /*int main(void) { fun(); fun(100); fun(100,200); fun(100,200,300); system("pause"); return 0; }*/ int main(void) { fun(3.3,4.4); fun(3,4); system("pause"); return 0; } void fun (int i,int j,int k) { cout<<i<<","<<j<<","<<k<<endl; } void fun (double i,double j) { cout<<i<<","<<j<<endl; } /* 编译时将函数体代码和实参代替函数调用语句,关键字:inline,效率高,有条件; 1内联编译是建议性的,由编译器决定; 2逻辑简单,调用频繁的函数建议使用内联。 3递归函数无法使用内联方式。 函数重载是通过实参类型和个数识别的:名称相同,参数可辨。 C++函数默认值如果有,必须后几个形参都有默认值。即有默认值的参数必须全部放在最右边 函数的默认值 无实参则使用默认值,有实参则覆盖默认值 声明写默认值,定义不写默认值,编译都能通过;查看全部
-
/*#include <iostream> #include <stdio.h> using namespace std; void fun (const int &a,const int &b); int main(void) { int x=3; int y=5; fun(x,y); cout<<x<<endl; cout<<y<<endl; system("pause"); return 0; } void fun (const int &a,const int &b) { a=10; b=20; } >d:\documents\visual studio 2010\projects\test\test\test.cpp(18): error C3892: “a”: 不能给常量赋值 >d:\documents\visual studio 2010\projects\test\test\test.cpp(19): error C3892: “b”: 不能给常量赋值 #include <iostream> #include <stdio.h> using namespace std; int main(void) { int x=3; int y=5; int const*p=&x; cout<<*p<<endl; p=&y; cout<<*p<<endl; system("pause"); return 0; }查看全部
-
const int *p=null;与 int const * p=null等价 不与 int *const p=null等价; const int * connst p=null;与 int const * const p=null等价 int x=3;const int *p =$x; //p=&y;正确//*p=4;错误 int x=3;int * const p=&x;//p=&y;将是错误的; const int x=3;const int * const p=$x; //p=&y;*p=4;都是错误的 int x=3;const int &y=x; //x=10;正确// y=20;错误 const int x=3;x=5//错误 int x=3;const int y=x;y=5;//错误 int x=3;const int *y=&x;*y=5//错误 int x=3,z=4; int * oonst y=&x;y=&z;//错误 const int x=3;const int &y=x;y=5;//错误 const int x=3; int *y=&x;//错误 int x=3;const int *y=&x//正确查看全部
-
#include <iostream> using namespace std; void fun(int &a,int &b) { int c=0; c=a; a=b; b=c; } int main(void) { int x=10,y=20; fun(x,y); cout<<x<<endl<<y<<endl; system("pause"); return 0; } /*#include <iostream> using namespace std; void fun(int *a,int *b) { int c=0; c=*a; *a=*b; *b=c; } int main(void) { int x=10,y=20; fun(&x,&y); cout<<x<<endl<<y<<endl; system("pause"); return 0; } #include <iostream> using namespace std; int main(void) { int a =10; int *p=&a; int *&q=p; *q=20; cout<<a<<endl; system("pause"); return 0; } #include <iostream> using namespace std; typedef struct { int x; int y; }Coor; int main(void) { Coor c1; Coor &c=c1; c.x =10; c.y =20; cout<<c1.x<<c1.y<<endl; system("pause"); return 0; } #include <iostream> using namespace std; int main(void) { int a =3; int &b=a;//引用必须初始化 b=10; cout<<a<<endl; system("pause"); } */查看全部
举报
0/150
提交
取消