Memset Question

Hi Guys,

I have a quick question. I am sorry in advance if it sounds little too stupid.

But in the code below, I am hoping that it will NULL the allocated memory right?

1
2
3
4
5
6
7
8
9
10
11
12
struct s {
char arr[100];
int i;
} ; 

int main() {

s *p = (s *) malloc (sizeof(s)); 
memset(p, NULL, sizeof(s)); 
return 0;

}


Thanks
I believe it will, though NULL is technically a null pointer, I think it will be cast to a 0
Thanks a lot sir.
Just as an FYI... the calloc function is equivalent to malloc followed by a memset to 0. callocl() has a slightly different usage though: it takes two parameters, one is a record size and the other a number of records.

Thanks jsmith !
Topic archived. No new replies allowed.