Page 1 of 1

[Resolved]memset problems

Posted: Fri Jun 27, 2003 10:50 pm
by bugzpodder
i sometimes get strange results when i try to use memset to initialize an array. if i have something like memset(arr,0,___) sometimes it doesnt initilize anything, and sometimes it initializes to strange values. what should the third parameter be? something like sizeof(int)*arraysize if my array is int?

Posted: Sat Jun 28, 2003 12:02 am
by turuthok
memset(arr, 0, sizeof(arr)) works for me ...

-turuthok-

Posted: Sat Jun 28, 2003 5:46 am
by kmhasan
as far as i know,

Code: Select all

memset(arr,0,sizeof(arr))
works when the memory allocation is static.

Code: Select all

memset(arr,0,sizeof(datatype)*arraysize)
should work for both static and dynamic allocation of memory.

Posted: Sat Jun 28, 2003 6:19 am
by bugzpodder
thanks you guys!