How to use memset function in two dimensional array for initialization of members in C? -
i want know how can use memset function in 2 dimensional array in c. don't want face garbage problem in array how have initialize array.
could explain me how achieve ?
if 2d array has static storage duration, default-initialized zero, i.e., members of array set zero.
if 2d array has automatic storage duration, can use array initializer list set members zero.
int arr[10][20] = {0}; // easier way // same memset(arr, 0, sizeof arr);
if allocate array dynamically, can use memset
set bytes zero.
int *arr = malloc((10*20) * (sizeof *arr)); // check arr null // arr --> pointer buffer set 0 // 0 --> value bytes should set // (10*20*) * (sizeof *arr) --> number of bytes set memset(arr, 0, (10*20*) * (sizeof *arr));
Comments
Post a Comment