diff options
author | haturatu <taro@eyes4you.org> | 2024-12-12 18:53:25 +0900 |
---|---|---|
committer | haturatu <taro@eyes4you.org> | 2024-12-12 18:53:25 +0900 |
commit | 2eb858c51eaf50a780ee47227963fcb36aac4102 (patch) | |
tree | 24691dc5a92e1eedee512e98a4d140b836b656d8 /calloc.c |
first commit
Diffstat (limited to 'calloc.c')
-rw-r--r-- | calloc.c | 23 |
1 files changed, 23 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> + +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 +} |