I have written a small program to get used to memset() operation:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> int main() { int arr[10], i; int t = INT_MAX; memset(arr, t, sizeof(arr)); for (i = 0; i < 10; i++) printf("%d\t",arr[i]); printf("%d",t); return 0; } The result of the above program is:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2147483647 What is the behaviour of the memset() in the above program? Why is it setting the array elements to -1?