blob: 1f3bf6697b2f9a67cbe8ce7e26004c564d1f9bd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}
|