The variables named in a structure are called members. A structure member or tag and an ordinary (i.e., non-member) variable can have the same name without conflict, since they can always be distinguished by context.
#include<stdio.h>
int a;
int main()
{
int a;
}
Here identifier 'a' is used twice but without conflicting,since they can always be distinguished by context. this will work for structers also.
Furthermore, the same member names may occur in different structures, although as a matter of style one would normally use the same names only for closely related objects.
#include<stdio.h>
int a;
int main()
{
struct s1
{
int a;
int c;
};
struct s2
{
int a;
int b;
};
}
Here identifier 'a' is used twice but with in different structures, therefore no conflict....
although as a matter of style one would normally use the same names only for closely related objects.
it means we generally doesn't use to avoid confusion
struct addpoint(struct point p1, struct point p2)
{
p1.x += p2.x;
p1.y += p2.y;
return p1;
}
Here p2 is only not copying inside p1 and also incrementing value
P2 doesn't copied... it's just accessing the variables like
a + = b ; ===> a = a+b; ===> here a is p1.x and b is p2.x