In C++, there is overloaded copy constructor and assignment overloading for a deep copy. Since default available is a shallow copy.
In C, the structure which has pointer member, if passed to a function or assigned to already created new struct object is a deep copy or shallow copy??
E.g
struct data {
int a;
int *b;
};
void test_func(struct data tes)
{
tes.a =3;
int *c = new int[1];
c[0]=2;
tes.b =c;
std::cout<<*tes.b;
}
int main() {
struct data test;
int *c = new int;
*c=4;
test.a = 1;
test.b =c;
std::cout<<*test.b;
test_func(test);
std::cout<<*test.b;
}