C Programming theory Questions and answers – Part 5

201. What is the difference between exit() and return() in c?
Answer : Exit() is a system call which terminates current process. Exit() is not an instruction of c language. Whereas, return() is a c language instruction/statement and it returns from the current function (I.E. Provides exit status to calling function and provides control back to the calling function).

202. What is the difference between memcpy() & strcpy() functions in c?
Answer : Memcpy() function is used to copy a specified number of bytes from one memory to another. Whereas, strcpy() function is used to copy the contents of one string into another string.
Memcpy() function acts on memory rather than value. Whereas, strcpy() function acts on value rather than memory.

203. What is the difference between memcpy() & memmove() functions in c?
Answer : Memcpy() function is is used to copy a specified number of bytes from one memory to another.
Memmove() function is used to copy a specified number of bytes from one memory to another or to overlap on same memory.
Difference between memmove() and memcpy() is, overlap can happen on memmove(). Whereas, memory overlap won’t happen in memcpy() and it should be done in non-destructive way.

204. Is there any inbuilt library function in C to remove leading and trailing spaces from a string? How will you remove them in C?
Answer : There is no inbuilt function to remove leading and trailing spaces from a string in c. We need to write our own function to remove them. We need to check first non-space character in given string. Then, we can copy that string from where non space character is found. Then, we can check whether any spaces are available in copied string from the end of the string. If space is found, we can copy ‘\0’ in that space until any character is found. Because, ‘\0’ indicates the end of the string. Now, we have removed leading and trailing spaces in a given string.

205. Can array subscripts have negative value in C ?
Answer : No. Array subscripts should not have negative value. Always, it should be positive.

COPY CODE SNIPPET