Q4, 7 MCQ- Pointers

Please explain Q4 and 7 of the MCQ- Pointers assignment

@shivanshu.khajuria
4. Ans : B

free() can be called for NULL pointer, so no problem with free function call. The problem is memory leak, p is allocated some memory which is not freed, but the pointer is assigned as NULL. The correct sequence should be following:

free(p);
p = NULL;

In this code *(arr+i)+(i++) this will results in the addresses where i can be 0,1,2 in the loop and * ( * (arr+i)+(i++)) results in the garbage values at these addresses and then we are simply adding these values using the variable sum.

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.