我无法将空指针返回到C中的另一个函数.
标头文件:
void *function2( void );
Run Code Online (Sandbox Code Playgroud)
MAIN.C
#include "myHeader.h"
void function1 (){
void *temp = NULL;
temp = function2();
}
Run Code Online (Sandbox Code Playgroud)
FUNCTION2.C
int a = 3;
void *function2(void){
printf("Memory Address %p\n",&a );
return (void *) &a; // value of &a is 0x100023444
}
Run Code Online (Sandbox Code Playgroud)
但是,function1()中temp的值是0x3444,而不是0x100023444.
有没有人知道这个解决方案,或者我做错了什么?
编辑:似乎,标题被添加到错误的位置,导致下面的AndreyT和Jonathan描述的问题,这似乎修复了截断问题.谢谢你的帮助!