I am incredibly new in C programming and I'm having a hard time understanding some aspects of it, including the strcpy()
function.
I am doing some quizzes and passed over the following question:
To assure the correctness of the following strcpy(d,s)
call, which of the following conditions must always be met:
a. sizeof(d) >= strlen(s) + 1
b. sizeof(d) >= sizeof(s)
c. sizeof(d) >= strlen(s)
d. strlen(d) >= strlen(s)
e. strlen(d) >= strlen(s) + 1
After doing some research, I found that the size of the destination string should be large enough to store the copied string. Source here. This led me to answers either b or d.
However the correct answer is 'a' and I cannot understand why, and cannot find any documentation. Could someone please explain in more details what the restrictions of strcpy()
are?