Hi All,
What is happening in the below piece of code
Its printing Hello, why not world. Its working like call by value. Please clarify me on this.
int main()
{
char *temp = (char *)malloc(sizeof ("Hello" + 1));
strcpy(temp, "Hello");
fun(temp);
printf("temp = %s\n", temp);
return 0;
}
void fun(char *temp)
{
temp = (char *)malloc(sizeof ("World" + 1));
strcpy(temp, "World");
}
What is happening in the below piece of code
Its printing Hello, why not world. Its working like call by value. Please clarify me on this.
int main()
{
char *temp = (char *)malloc(sizeof ("Hello" + 1));
strcpy(temp, "Hello");
fun(temp);
printf("temp = %s\n", temp);
return 0;
}
void fun(char *temp)
{
temp = (char *)malloc(sizeof ("World" + 1));
strcpy(temp, "World");
}
Comment