Memst function and array declaration

how memset function works and why we declare both the arrays before main function

memset is used in c++ to set the array with a particular value .
like we want to intialise the whole array with -1 then instead of running the loop of array size we can do like memset(arr,-1,sizeof(arr)).

maybe it is being used in some other function

if this solves your doubt please mark it as resolved and rate as well :slight_smile:

Hey @TheSourabh
What is the issue?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

we can directly even assign a[100] ={0} then also it assign all the values of array to be 0 then what is the need of memset function

That works for 0 only

But what if u want to set something else
like 1 or 2 or some other integer
in that case memset is used