I'm preparing for an interview and came across a practice question that I could not figure out. Here is the code:
#include <stdio.h>
int main()
{
char *p,*q;
p=(char *)malloc(25);
q=(char *) malloc(25);
strcpy(p,"amazon" );
strcpy(q,"hyd");
strcat(p,q);
printf("%s\n",p);
}
I compiled it and executed it, but it worked just fine. There is a problem with the code, which makes me suspect it has something to do with uninitialized variables. The output is amazonhyd like it should be. Could someone let me know what I'm missing?
edit: This is a practice interview question, and the question is asking what is wrong with in this code.