Yes, There is no copies, just the pointers.
And Thanks your support I was able to proceed this.
As you can see the code in the function 'fun' and 'fun_one' both of their return type is pointer pointing the location of the value.
as you can see in the 'printf' statement, those function are orderly executed from the left to right
First 'fun_one' which change the value of name as 'Mike' and return its pointer location not the data,
then the function 'fun' is executed where the value of name is changed to 'Thomas' and return the pointer location not the data. Now both the fun and fun_one points towards the same location but the current value of that pointer is 'Thomas'.
So as further execution of the printf goes, it will display two strings which at the pointer location which is 'Thomas'. so 'Thomas' is printed two times as 'ThomasThomas'.
similarly, if i change the position of function call in printf statement as
C:
printf("%s%s",fun_one(&std),fun(&std));
then it will display as 'MikeMike', since 'fun_one' changes the name as 'Mike' so at the pointer location only Mike is stored thats why 'Mikemike' is printed.
huff.... i tried to debug that code by adding printf statement as below.
C:
#include <stdio.h>
#include <string.h>
struct student{
char name[20];
}std;
char *fun(struct student *tempstd){
printf("1. %s \n",tempstd->name);
strcpy(tempstd->name,"MIKE");
printf("2. %s \n",tempstd->name);
return tempstd->name;
}
char *fun_one(struct student *tempstd){
printf("1. %s \n",tempstd->name);
strcpy(tempstd->name,"THOMAS");
printf("2. %s \n",tempstd->name);
return tempstd->name;
}
int main()
{
printf("Hello World\n");
strcpy(std.name,"mike2p");
printf("0.%s%s%s \n",std.name,fun_one(&std),fun(&std));
return 0;
}
/*output
Hello World
1. mike2p
2. MIKE
1. MIKE
2. THOMAS
0.THOMASTHOMASTHOMAS*/
well, if you ask me what i learned, its that in printf statement, the exection order is from left to right. and then print it in the order we specified. and the pointer of struct pointers.
I also thought the pritf sequence changes form compiler to compiler, i tried various compiler GCC, Turboc, codeblock ide and online platform too. were all of them gave the same output.
and please correct me if i gone wrong some where.