From 2eb858c51eaf50a780ee47227963fcb36aac4102 Mon Sep 17 00:00:00 2001 From: haturatu Date: Thu, 12 Dec 2024 18:53:25 +0900 Subject: first commit --- realloc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 realloc.c (limited to 'realloc.c') diff --git a/realloc.c b/realloc.c new file mode 100644 index 0000000..e0caf86 --- /dev/null +++ b/realloc.c @@ -0,0 +1,22 @@ +#include +#include + +int main() +{ + char *mem_allocation; + + // 動的メモリ確保 + mem_allocation = malloc(20 * sizeof(char)); + if (mem_allocation == NULL) { + fprintf(stderr, "メモリ確保失敗\n"); + return 1; + } + + // 動的メモリ再確保 + mem_allocation = realloc(mem_allocation, 40 * sizeof(char)); + if (mem_allocation == NULL) { + fprintf(stderr, "メモリ確保失敗\n"); + return 1; + } + free(mem_allocation); +} -- cgit v1.2.3