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 /memset.c |
first commit
Diffstat (limited to 'memset.c')
-rw-r--r-- | memset.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/memset.c b/memset.c new file mode 100644 index 0000000..06db271 --- /dev/null +++ b/memset.c @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main() +{ + int i; + char *a = malloc(5 * sizeof(char)); + + // 配列の要素を全て0に設定 + memset(a, 0, 5*sizeof(char)); + + for (i = 0; i < 5; ++i) { + printf("a[%d] = %d,", i, a[i]); + } + + // => a[0] = 0, a[1] = 0, a[2] = 0, a[3] = 0, a[4] = 0, + free(a); +} |