summaryrefslogtreecommitdiff
path: root/realloc.c
blob: e0caf86faef001900d7b178b41d726122ed46bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <stdlib.h>

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);
}