Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How default assignment operator works in struct?

Tags:

c++

Suppose I have a structure in C++ containing a name and a number, e.g.

struct person {

char name[20];

int ssn;

};

Suppose I declare two person variables:

person a;

person b;

where a.name = "George", a.ssn = 1, and b.name = "Fred" and b.ssn = 2.

Suppose later in the code

a = b;

printf("%s %d\n",a.name, a.ssn);
like image 782
skydoor Avatar asked Mar 20 '10 17:03

skydoor


1 Answers

The default assignment operator does a member-wise recursive assignment of each member.

like image 125
Jonathan Leffler Avatar answered Nov 07 '22 04:11

Jonathan Leffler