char str[] = \"beautiful earth\";
memset(str, \'*\', 6);
printf(\"%s\", str);
Output:
******ful earth
Like the above use of memset, can we initial
Since nobody mentioned it...
Although you cannot initialize the integers with value 1
using memset, you can initialize them with value -1
and simply change your logic to work with negative values instead.
For example, to initialize the first 6 numbers of your array with -1
, you would do
memset(arr,-1,6*(sizeof int));
Furthermore, if you only need to do this initialization once, you can actually declare the array to start with values 1
from compile time.
int arr[15] = {1,1,1,1,1,1};