C语言 malloc()与sizeof运算的盲点

时间:2023-03-08 22:03:08
//malloc()与sizeof运算的盲点
#include <stdio.h>
#include <stdlib.h>
#include <string.h> void main()
{
char *p = (char *)malloc(sizeof(char)*);
printf("%d\n",siezof(p));//打印4
/*
malloc函数分配的内存,使用memset()函数的时候要注意,
指针p的大小是4个字节,不要使用sizeof(p),这是错误的
*/
memset(p, , sizeof(p));//错误
free(p);
system("pause");
}