Using memset for integer array in c
char str[]="beautiful earth"; memset(str,'*',6); printf("%s",str); output: ******ful earth 1) Like above use of memset, can we initialize only few integer array index values to 1 as given below?? int arr[15]; memset(arr,1,6); No, you cannot use memset() like this. The manpage says (emphasis mine): The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c . Since an int is usually 4 bytes, this won't cut it. If you ( incorrectly!! ) try to do this: int arr[15]; memset(arr, 1, 6*sizeof(int)); //wrong! then the first 6 int s in the array will