Using memset for integer array in C

前端 未结 10 1730
遇见更好的自我
遇见更好的自我 2020-11-27 02:20
char str[] = \"beautiful earth\";
memset(str, \'*\', 6);
printf(\"%s\", str);

Output:
******ful earth

Like the above use of memset, can we initial

10条回答
  •  我在风中等你
    2020-11-27 03:09

    On Linux, OSX and other UNIX like operating systems where wchar_t is 32 bits and you can use wmemset() instead of memset().

    #include
    ...
    int arr[15];
    wmemset( arr, 1, 6 );
    

    Note that wchar_t on MS-Windows is 16 bits so this trick may not work.

提交回复
热议问题