What is the error in the code below and how should it be cor

What is the error in the code below and how should it be corrected?

Solution

Answer:


In this code, what you are using argument memset is not correct.

sizeof(bar) is the size of a pointer. it calculates the size of bar (i.e., the pointer itself) rather than the size of the structure pointed to by bar.

We have to use sizeof(*bar) i.e., size of an object.

The correct syntax is   memset(bar, 0, sizeof(*bar));

What is the error in the code below and how should it be corrected?SolutionAnswer: In this code, what you are using argument memset is not correct. sizeof(bar)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site