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

静态全局指针变量的小疑点 急

2012-04-17 
静态全局指针变量的小问题 急!!!#includestdio.h#includestdlib.hstatic int *pvoid test1(){int a1

静态全局指针变量的小问题 急!!!
#include<stdio.h>
#include<stdlib.h>

static int *p;
void test1()
{
int a=10;
p=&a;
printf("%d\n",*p);
}
void test2()
{
int *q;
q=p;
printf("%d\n",*q);
}
int main(void)
{
test1(); //输出10
test2(); //这里指针p怎么又为空了呢?

return 0;
}


[解决办法]
指针p并没有空,但它所指向的地方已经无效了。
[解决办法]
这是因为在create方法中你改变了它。
pro->next=pro->next->next;

热点排行