From 2eb858c51eaf50a780ee47227963fcb36aac4102 Mon Sep 17 00:00:00 2001 From: haturatu Date: Thu, 12 Dec 2024 18:53:25 +0900 Subject: first commit --- calloc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 calloc.c (limited to 'calloc.c') diff --git a/calloc.c b/calloc.c new file mode 100644 index 0000000..1f3bf66 --- /dev/null +++ b/calloc.c @@ -0,0 +1,23 @@ +#include +#include + +int main() +{ + char *mem_allocation; + + // 動的メモリ確保(0で初期化) + mem_allocation = calloc(20, sizeof(char)); + if (mem_allocation == NULL) { + fprintf(stderr, "メモリ確保失敗\n"); + return 1; + } else { + mem_allocation[0] = 't'; + mem_allocation[1] = 'e'; + mem_allocation[2] = 's'; + mem_allocation[3] = 't'; + } + + printf("格納した文字列 : %s\n", mem_allocation); + free(mem_allocation); + // => test +} -- cgit v1.2.3