#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void testPtr1(char**dbuser)//指向*dbuser地址
{
*dbuser = (char*)calloc(strlen("dbuser") + 1, sizeof(char));
strcpy(*dbuser, "dbuser");
}
void testPtr2(char*&dbuser)//指向取*dbuser地址
{
dbuser = (char*)calloc(strlen("dbuser") + 1, sizeof(char));
strcpy(dbuser, "dbuser");
}
void getPtr1()
{
char *dbuser = NULL;
testPtr1(&dbuser);//取*dbuser地址
printf("%s\n", dbuser);
if (dbuser != NULL)free(dbuser); dbuser = NULL;
}
void getPtr2()
{
char *dbuser = NULL;
testPtr2(dbuser);//传*dbuser地址
printf("%s\n", dbuser);
if (dbuser != NULL)free(dbuser); dbuser = NULL;
}
int main()
{
getPtr1();
getPtr2();
system("pause");
return 0;
}
指针与引用
最新推荐文章于 2022-08-16 17:20:27 发布