首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

c语言的指针有关问题,在这好纠结,

2012-04-13 
c语言的指针问题,在这好纠结,在线等。。。。#includestdio.hvoid test(int *p){int *qq(int *)malloc(size

c语言的指针问题,在这好纠结,在线等。。。。
#include<stdio.h>
void test(int *p)
{
int *q;
q=(int *)malloc(sizeof(int));
*q=10;
p=q;
printf("%d\n",*p); //程序执行到此出指针q已经赋值,能打印出来数值10,问题在主函数
}
int main(void)
{
int *st;
st=NULL;
test(st);
printf("%d\n",*st); //跳出test(st)函数后,st指针怎么又变为空了呢???打印不出来。。。。
return 0;

}


问题在主函数的注释

求解! 感谢!

[解决办法]
形参是不能改变他的值得。。。
[解决办法]
上一楼贴错代码了...

C/C++ code
#include<stdio.h>#include <stdlib.h>void test(int **p){  int *q;  q=(int *)malloc(sizeof(int));  *q=10;  *p=q;  printf("%d\n",**p);}int main(void){  int *st;  st=NULL;  test(&st);  printf("%d\n",*st);  return 0;  } 

热点排行