char str[] = \"beautiful earth\";
memset(str, \'*\', 6);
printf(\"%s\", str);
Output:
******ful earth
Like the above use of memset, can we initial
The third argument of memset is byte size. So you should set total byte size of arr[15]
memset(arr, 1, sizeof(arr));
However probably, you should want to set value 1 to whole elements in arr. Then you've better to set in the loop.
for (i = 0; i < sizeof(arr)/sizeof(arr[0]); i++) {
arr[i] = 1;
}
Because memset()
set 1 in each bytes. So it's not your expected.