[Resolved]memset problems

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

[Resolved]memset problems

Post 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?
Last edited by bugzpodder on Mon Jul 28, 2003 4:54 pm, edited 1 time in total.
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

memset(arr, 0, sizeof(arr)) works for me ...

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
kmhasan
Problemsetter
Posts: 107
Joined: Fri Oct 26, 2001 2:00 am
Location: Canada
Contact:

Post 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.
bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

Post by bugzpodder »

thanks you guys!
Post Reply

Return to “C++”