void swap(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
}
a,b交换
#include "iostream.h"
void swap(int x,int y);
void main()
{
int a=2,b=3;
swap(a,b);
cout <<"a=" <<a <<endl;
cout <<"b=" <<b <<endl;
}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
a,b没有交换
3.直接或间接的在函数体内调用函数本身的现象称为函数的递归。
4.指针存储的是值的地址。是一个变量。
当我们要声明多个指针变量时,必须在每个指针变量名前加上*
int *p1,*p2,p3 //p1,p2都是指向整型变量的指针变量,而P3是整型变量。
空指针,int* p1 =NULL; //c++大小写敏感,NULL与null是不同的。
*,解引用操作符,获取指针所指向的变量或存储空间。
#include "iostream.h"
void main()
{
int i=3;
int *iptr=&i;
int **iptrptr=&iptr; //iptr也是变量,也能够获取它的地址。
cout <<"Address of Var i=" <<iptr <<endl;//输出iptr存储的内容,即i在内存中的地址。
cout <<"Data of Var i=" <<*iptr <<endl;//输出iptr所指向的变量
cout <<"Address of Pointer iptr=" <<iptrptr <<endl;//输出iptr在内存中的地址
cout <<"Address of Var i=" <<*iptrptr <<endl;//输出iptr所指向的变量,即iptr
*iptr=2+*iptr;
cout <<"Data of Var i=" <<*iptr <<endl;
}