Q:
What would be the output of the following program?
main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = { "Dravid", 23};
struct emp e2 = e1;
strupr (e2.n);
printf ("\n%s",e1.n);
}
Answer
DRAVID
When a structure is assigned, passed, or returned, the copying is done monolithically. This means that the copies of any pointer fields will point to the same place as the original. In other words, anything pointed to is not copied. Hence, on changing the name through e2.n it automatically changed e1.n
View answer
Workspace
Report Error
Discuss