#define _CRT_SECURE_NO_WARNINGS//强行去掉安全检查
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
char *get_men(int size)
{
char *p2 = (char *)malloc(size); //分配内存空间
return p2;
}
void main()
{
char buf[100];
int a = 10;
int *p = &a;
*p = 20;
char *mp = get_men(100);
strcpy(mp,"chenqi");
printf("mp=%s\n", mp);
if (mp != NULL)
{
printf("bufore=%d\n", mp);
//printf("bufore=%d\n,%s", mp,mp);
free(mp);//告诉系统,mp指向的内存可以被别人使用了
printf("bufore=%d\n", mp);
//释放完,mp就是野指针,还是保存着之前的地址,最好赋值为NULL
mp = NULL;
}
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
char *get_men(int size)
{
char *p2 = (char *)malloc(size); //分配内存空间
return p2;
}
void main()
{
char buf[100];
int a = 10;
int *p = &a;
*p = 20;
char *mp = get_men(100);
strcpy(mp,"chenqi");
printf("mp=%s\n", mp);
if (mp != NULL)
{
printf("bufore=%d\n", mp);
//printf("bufore=%d\n,%s", mp,mp);
free(mp);//告诉系统,mp指向的内存可以被别人使用了
printf("bufore=%d\n", mp);
//释放完,mp就是野指针,还是保存着之前的地址,最好赋值为NULL
mp = NULL;
}
system("pause");
}