strcpy function in CodeBlocks with MinGW is not behaving properly. It is modifying the constant string when the Destination has less space than source string. According to standards, if Destination has less space than source the behavior is undefined, but why Source(S), which is a accepted as constant by strcpy function, is getting modified?
#include<string.h>
#include<stdio.h>
int main(){
char S[]="Computer";
char D[]="";
strcpy(D,S);
printf("%s\n",S);
return 0;
}
Output: When size of D(Destination) is equal or more than size of S(source)
Output: When size of D is less than size of S
Output: Omputer [When size of D is not specified]