【发布时间】:2011-08-18 02:11:52
【问题描述】:
各位,ptr 是如何得到它之前的值的呢?代码很简单,我只是想知道为什么它不存储在函数中分配的地址值。
#include<stdio.h>
#include<stdlib.h>
void test(int*);
int main( )
{
int temp;
int*ptr;
temp=3;
ptr = &temp;
test(ptr);
printf("\nvalue of the pointed memory after exiting from the function:%d\n",*ptr);
printf("\nvalue of the pointer after exiting from the function:%d\n",ptr);
system("pause ");
return 0;
}
void test(int *tes){
int temp2;
temp2=710;
tes =&temp2;
printf("\nvalue of the pointed memory inside the function%d\n",*tes);
printf("\nvalue of the pointer inside the function%d\n",tes);
}
输出是:
函数内指向内存的值:710
函数内指针的值:3405940
函数退出后指向内存的值:3
退出函数后指针的值:3406180
【问题讨论】: