diff options
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 +} |