C 语言函数值传递和指针传递区别

 时间:2024-10-12 09:29:02

1、#include <stdio.h>#include <挢旗扦渌;stdlib.h>#include <string.h>//值传递时,并不改变实参的值void getmemory(char *p){ p=(char *) malloc(100); strcpy(p, "hello world");}int main(){ char *str=NULL; getmemory(str); printf("%s",str); free(str); return 0;}并且每次调用函数,都会泄露100大小内存空间

C 语言函数值传递和指针传递区别

2、#include <stdio.h>#include <stdlib.h>#include <string.h>//实参地址作为参数传递,可以改变实参的值void getmemory(char **p){ *p=(char *) malloc(100); strcpy(*p,"hello world");}int main(){ char *str=NULL; getmemory(&str); printf("%s\n",str); free(str); return 0;}

C 语言函数值传递和指针传递区别
  • 成都市郫都区三道堰青杠树景区周末游
  • 四川绵阳唐讯科目三:道路路口图景。
  • 坦克300防冻液放水口在哪里
  • 小米平板黑屏怎么设置双击唤醒屏幕
  • 天玑最新处理器是多少
  • 热门搜索
    噗嗤是什么意思 耳熟能详的意思 不同凡响的意思 什么是普通住宅 开花店需要准备什么 like是什么意思 as是什么意思 破釜沉舟的意思 荒芜的意思 any是什么意思