When I compile this code, the lastName variable is changed the third time I ask it to print it before telling it to change. What is causing this to happen?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char firstName[] = "Bill";
char middleName[] = "Bryan";
char lastName[] = "Max";
char fmName[] = {};
char fmlName[] = {};
printf("%s\n", lastName);
strcat(firstName, middleName);
printf("%s\n", lastName);
strcpy(fmName, firstName);
printf("%s\n", lastName);
strcat(fmName, lastName);
printf("%s\n", fmName);
return 0;
}
OUTPUT
>>> Max
>>> Max
>>> BillBryan // <- Why is it printing that lastName is this value when I did not change it?