- is malloc() needed for char*[]`
There is hardly ever a need for malloc in C++.
In C, you usually do need malloc, but only if you need to allocate dynamically.
In general, having a char*[] does not mean that you necessarily need dynamic allocation and thus no need for malloc.
if i do not malloc for every element of array str[] , then wouldn't it be wrong to assign a string without allocating memory for this string?
A char* does not need to point to memory allocated with malloc. It can for example point directly to a string literal (only in C; in C++ you need a pointer to const). Or it can point to memory on the stack.
isn't char *str; strcpy(str,"sample") wrong if i dont allocate memory to str through malloc?
That is wrong, but not because you don't use malloc. It is wrong because you pass an uninitalised pointer to strcpy. Therefore the behaviour is undefined. It has nothing to do with malloc.
- would strcmp fail ...
It is unclear what you mean by "fail". There is no output that signifies a failure or error. For some inputs, the behaviour is undefined. While undefined behaviour is a failure of the programmer, there is no guarantee of behaviour that you might consider a failure.
... if i memset to 0?
If you pass a pointer to strcmp that is not a pointer to a null terminated string, then the behaviour of the program is undefined.
In the program that you show, you end up passing uninitialised pointer, or one that was memset to 0, and there is therefore no guarantee for them to be a pointer to a null terminated string. Therefore the behaviour of the program is undefined.
i'm passing a pointer pointing to 0(null), so dereferencing shouldn't face the problem of having no null terminated string right as we dont store anything in null location
Memset to 0 is not guaranteed to be null, as far as the standard is concerned. Even if probably is null on your system, 10 bytes is probably not enough for 4 pointers on that system, as pointed out by @ChristianGibbons, so you haven't actually initialised all of the pointers at all.
Even if you did initialise the pointers to null, a null pointer is not a pointer to a null terminated string, and therefore passing a null pointer to strcmp has undefined behaviour.