为什么malloc在GCC中将值初始化为0?
#include <stdio.h>#include <stdlib.h>int main(){ double *a = (double*) malloc(sizeof(double)*100) printf("%f", *a);}
int main(){ int *a = (int*) malloc(sizeof(int)*200000); a[10] = 3; printf("%d", *(a+10)); free(a); a = (double*) malloc(sizeof(double)*200000); printf("%d", *(a+10));}OUTPUT: 3 0 (initialized)
Cats萌萌
湖上湖
莫回无