指针做函数参数的输入输出特性
输入特性:
输出特性:
代码示例:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void func(char*p)
{
strcpy(p,"hello world");
}
void test01()
{
char buf[1024] = {
0};
func(buf);
printf("%s\n",buf);
}
void printString(char *str)
{
printf("%s\n",str);
}
void test02()
{
char*p = malloc(sizeof(char)*64);
memset(p,0,64);
strcpy(p, "hello world");
printString(p);
}
void allocateSpace(char**pp)
{
char *temp = malloc(sizeof(char)*64);
memset(temp, 0, 64);
strcpy(temp, "hello world");
*pp = temp;
}
void test03()
{
char*p = NULL;
allocateSpace(&p);
printf("%s\n",p);
}
int main()
{
test03();
return EXIT_SUCCESS;
}
更多文章,敬请关注微信公众号:YQ编程