Alo explain why we are using memset in this question
Please explain what is memset function,its syntax and everything
We can use memset() to set all values as 0 or -1 for integral data types also. It will not work if we use it to set as other values. The reason is simple, memset works byte by byte.
syntax
memset
(a, 0,
sizeof
(a));
more detail explanation
Memset in C++
Converts the value ch to unsigned char and copies it into each of the first n characters of the object pointed to by str[]. If the object is not trivially-copyable (e.g., scalar, array, or a C-compatible struct), the behavior is undefined. If n is greater than the size of the object pointed to by str, the behavior is undefined.
Template
void* memset( void* str, int ch, size_t n);
** Parameters
str[] : Pointer to the object to copy the character.
ch : The character to copy.
n : Number of bytes to copy.
Return value : The memset() function returns str, the pointer to the destination string.
why we used it in above video when we can just do that by ar[5]={0} or ar[5]={-1}
int arr[5]={};
this will work only at the time of declaration
as arrays are global so after each testcase we have to reset them
for that either make a loop or use memset no matter both will work similarly
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.