Take a look at this piece of code:
and here is the output:Code:int main (int argc, char *argv[]) { char *str1 = "Foxbat"; char *str2 = "Fulcrum"; printf("str1 = %s\tstr2 = %s\n", str1, str2); strncat(str1, "ABC", 2); printf("str1 = %s\tstr2 = %s\n", str1, str2); return 0; }
why is str2 being spoiled?? it is not supposed to contain value B, right? Any ideas?...i tried to declare str2 as const...but same result..Code:str1 = Foxbat str2 = Fulcrum str1 = FoxbatAB str2 = B