Desc :

 void *calloc(size_t num, size_t size );

 

size_t : 객체의 크기를 나타내기 위해서 쓰이는 16비트 이상의 unsigned int타입

num - 동적으로 할당할 블록의 수

size - 블록의 크기

 

num*size 만큼의 메모리를 할당할 수 있다

malloc와 달리 할당된 버퍼를 모두 0으로 초기화함

 


Source Code :

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

void main()
{
	char *pmem;	// 메모리를 가리킬 포인터 변수

	printf("sizeof(int)의 길이는 %d입니다.\n", sizeof(int));

	pmem = calloc(100, sizeof(int));

	if (pmem == NULL)
	{
		puts("메모리를 할당할 수 없습니다.");
	}
	else
	{
		puts("정수형 변수 100개를 저장할 버퍼가 할당되었습니다.\n");

		free(pmem);
	}
}

 


Result :

 

 

+ Recent posts