有下列简单的C程序,想一想程序运行的结果是什么?
#include<stdio.h>
#include<stdlib.h>
int *p;
//p=NULL (1)
void test_p(int *p){
p=(int *)malloc(sizeof(int));
if(!p){
perror("malloc faild/n");
}else{
printf("in test_p *p=%d/n“,*p=3);
}
}
void init_p(){
p=(int *)malloc(sizeof(int));
if(!p){
perror("in init_p malloc faild/n");
}else{
printf("in init_p p=%X *p=%d/n",(unsigned)p,*p=4);
}
}
int main(){
test_p(p);
if(!p){
printf("after executed test_p p is NULL/n");
}else{
printf("after executed test_p *p=%d/n",*p=4);
}
return 0;
}
1) 输出结果是
C指针的疑惑(函数传址调用,如果传递的指针没有初始化会怎么样?)
最新推荐文章于 2023-03-28 17:03:41 发布
有下列简单的C程序,想一想程序运行的结果是什么?#include#includeint *p;//p=NULL (1)void test_p(int *p){ p=(int *)malloc(sizeof(int)); if(!p){ perror("malloc faild/n"); }else{ pri
摘要由CSDN通过智能技术生成