Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
char str[20];
memset(&str, 0, sizeof(str));

any issue will cross over it.
because for char array memset(&str, '\0', strlen(str)); literally lot of people use it.
so that am asking ?...please clarify it...

What I have tried:

i described my issue and my checking any segmentation issue will come in or not
Posted
Updated 6-Oct-21 20:42pm

No problem at all.
Yours is the correct way.
 
Share this answer
 
No, it correct. In more complex scenarios you must use the byte size of that memory block.

A nice shorthand is
C++
char str[20] = {0};
which enforces such a memset without further code.
 
Share this answer
 
Comments
CPallini 7-Oct-21 2:49am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900