值交换传参
void swap(int, int) //值传递
void swap(int*, int*) //地址传递
void swap(int&, int&) //引用传递
指针的指针传参
#include <iostream>
#include <string>
void find2(char array[], char search, char **ppa);
using namespace std;
int main() {
char str[] = {"afsdfsdfdf\0"};
char a = 'd';
char *p = 0;
find2(str, a, &p);//find2(str, a, p);传递的是初始化0内存空间的地址,&p才是指针p的地址
if (0 == p)
{
printf("没找到!\n");
}
else
{
printf("找到了,p = %d", *p);
}
return 0;
}
void find2(char array[], char search, char **ppa)
{
int i;
for (i=0; *(array + i) != 0; i++)
{
if(*(array + i) == search)
{
*ppa = array + i;
break;
}
else if(*(array + i) == 0)
{
*ppa = 0;
break;
}
}
}
标签:char,ppa,int,void,c++,参数传递,array,find2
From: https://www.cnblogs.com/liubenben/p/17935783.html