C question from an interview -
in lines code fail (meaning: don't supposed do), , why?
int main(void) { char student[64] = "some guy"; char* teacher; /* line1 */ strcpy(teacher, student); /* line2 */ teacher=student; /* line3 */ strcpy(student, "alber einstein"); /* line4 */ student = teacher; }
line 1 causes undefined behaviour. line 4 won't compile. since seems homework question, , don't give whole thing away, quick read of comp.lang.c faq or c language specification explain why.
Comments
Post a Comment