Why are we using type casting in memory management in C and what is?
My answer to your first part of the question:The malloc() and calloc() returns void* which can be assigned to any pointer type. void *malloc(size_t size); void *calloc(size_t nmemb, size_t size);void* is returned by both the functions here.-In C it's not necessary to cast the void* since it's implicitly done by compiler.-But in C++ it will give you an error if you don't typecast it. So, in C++ it is mandatory to cast-If the memory is not allocated due to some error then the NULL is returned by the memory management functions. Now coming to the second part of your question:i) puts(str);ii) printf(str);puts() can be preferred for printing a string because it is generally less expensive (implementation of puts() is generally simpler than printf()), and if the string has formatting characters like %, then printf() would give unexpected results.Also note that puts() moves the cursor to next line i.e., it automatically appends a newline. One more difference is that puts() returns a non-negative integer if successful or EOF if unsuccessful; while printf() returns the number of characters printed (not including the trailing null). printf() is a more powerful version of puts(). printf() provides the ability to format variables for output using format specifiers such as %s, %d, etc. int puts(const char *s);puts() writes the string s and a trailing newline to stdout. int printf(const char *format, ...);The function printf() writes output to stdout, under the control of a format string that specifies how subsequent arguments are converted for output.