C编程:malloc()在另一个函数中
malloc()
在另一个函数中.
main()
malloc()
main()
.
资料来源:
int main(){ unsigned char *input_image; unsigned int bmp_image_size = 262144; if(alloc_pixels(input_image, bmp_image_size)==NULL) printf("\nPoint2: Memory allocated: %d bytes",_msize(input_image)); else printf("\nPoint3: Memory not allocated"); return 0;}signed char alloc_pixels(unsigned char *ptr, unsigned int size){ signed char status = NO_ERROR; ptr = NULL; ptr = (unsigned char*)malloc(size); if(ptr== NULL) { status = ERROR; free(ptr); printf("\nERROR: Memory allocation did not complete successfully!"); } printf("\nPoint1: Memory allocated: %d bytes",_msize(ptr)); return status;}
Point1: Memory allocated ptr: 262144 bytesPoint2: Memory allocated input_image: 0 bytes
BIG阳
慕田峪9158850
aluckdog