기능 요약
동적할당한 메모리를 크기를 조절하여 동적할당하는 함수
헤더파일
#include<stdlib.h>
원형
void* realloc(void* ptr, size_t size);
반환값
동적 할당한 메모리 공간의 시작 주소를 반환
할당 실패 시 NULL 반환
주의 사항
만약 할당한 부분 이외에 값을 대입하면 정의되지 않은 동작이 발생할 수 있습니다!
예시 코드
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int main(){
int *num = (int *)malloc(sizeof(int));
printf("%p\n",num);
num = realloc(num, sizeof(2*sizeof(int)));
printf("%p\n", num);
}
'C & C++ > c언어 표준함수' 카테고리의 다른 글
c) calloc() (0) | 2024.05.28 |
---|---|
c) strcat() (0) | 2024.05.28 |
c) strstr() (0) | 2024.05.28 |
c) getchar() (0) | 2024.05.28 |
c) puts() (0) | 2024.05.28 |