summaryrefslogtreecommitdiff
path: root/realloc.c
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2024-12-12 18:53:25 +0900
committerhaturatu <taro@eyes4you.org>2024-12-12 18:53:25 +0900
commit2eb858c51eaf50a780ee47227963fcb36aac4102 (patch)
tree24691dc5a92e1eedee512e98a4d140b836b656d8 /realloc.c
first commit
Diffstat (limited to 'realloc.c')
-rw-r--r--realloc.c22
1 files changed, 22 insertions, 0 deletions
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 <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);
+}