When a structure is assigned, passed, or returned, the copying is done monolithically....what does this monolithic mean
any example??

When a structure is assigned, passed, or returned, the copying is done monolithically....what does this monolithic mean
any example??

It means that every member variable gets copied over.

For example, this C code:

#include <stdio.h>

struct cat {
    int id_num;
    int age;
    int HP;
    int MP;
};

int main(void) {

    struct cat x;
    struct cat y;

    x.id_num = 1; x.age = 2; x.HP = 3; x.MP = 4;

    y = x;

    /* Now y.id_num == 1, y.age == 2, ... */

    printf("%d %d %d %d\n", y.id_num, y.age, y.HP, y.MP);
    /* Prints "1 2 3 4\n" */

    return 0;
}

What about pointers...anything pointed by pointers???.....if possible by example

What about pointers...anything pointed by pointers???.....if possible by example

Consider a structure of the form

struct dog {
    type_1 val_1;
    type_2 val_2;
    type_3 val_3;
    .
    .
    .
    type_n val_n;
};

The expression "x = y;", where x and y are of type struct dog, could be written as the following:

x.val_1 = y.val_1;
x.val_2 = y.val_2;
x.val_3 = y.val_3;
.
.
.
x.val_n = y.val_n;

So pointers would get copied, yes. They would contain the same memory address.


Remember that in C++ (but not C), structures can have copy constructors, which change this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.