summaryrefslogtreecommitdiff
path: root/memset.c
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2024-12-12 18:53:25 +0900
committerhaturatu <taro@eyes4you.org>2024-12-12 18:53:25 +0900
commit2eb858c51eaf50a780ee47227963fcb36aac4102 (patch)
tree24691dc5a92e1eedee512e98a4d140b836b656d8 /memset.c
first commit
Diffstat (limited to 'memset.c')
-rw-r--r--memset.c19
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);
+}