1,代码问题:
新建 gdb.c
#include<stdio.h>
#include<stdint.h>
#include<stdlib.h>
//#include <sharemem.h>
void fun(uint8_t* p)
{
uint8_t a = 100;
*p = a;
}
void fun1(int* p)
{
int b = 999;
*p = b;
}
int main()
{
uint8_t *p = (uint8_t*)malloc(sizeof(uint8_t*));
uint8_t a;
p = &a;
fun(p);
printf("a=%d\n",a);
free(p);
p = NULL;
int* q1 = (int*)malloc(sizeof(int*));
int g;
q1 = &g;
fun1(q1);
printf("g=%d\n",g);
free(q1);
return 0;
}
运行代码情况如下: