struct Person {
    char name[20];
    int age;
    float height;
};//int32_t

Example 1:

c
Copy code
struct Employee {
    int id;
    char name[20];
    float salary;
};

size_t size = sizeof(struct Employee);
In this example, we have defined a struct Employee with three data members: 
an integer id, a character array name of size 20, and a float salary. Assuming 
a 4-byte alignment requirement, the size of the struct would be 32 bytes: 4 bytes
for the id integer, 20 bytes for the name character array (which is padded with 
an additional 2 bytes to align the salary float on a 4-byte boundary), and 4 bytes
for the salary float.

Example 2:

c
Copy code
struct Point {
    float x;
    float y;
};

struct Rectangle {
    struct Point topLeft;
    struct Point bottomRight;
};

size_t size = sizeof(struct Rectangle);
In this example, we have defined a struct Point with two float data members x and 
y, and a struct Rectangle with two struct Point data members topLeft and 
bottomRight. Assuming a 4-byte alignment requirement, the size of the struct
Point would be 8 bytes (2 floats), and the size of the struct Rectangle would
be 16 bytes (2 struct Points, each of size 8 bytes).

Example 3:

c
Copy code
struct Node {
    int value;
    struct Node *next;
};

size_t size = sizeof(struct Node);
In this example, we have defined a struct Node with an integer data member value
and a pointer data member next that points to another struct Node. Assuming a
4-byte alignment requirement, the size of the struct Node would be 8 bytes (4 bytes
for the int data member, and 4 bytes for the pointer). Note that the size of the 
struct Node does not include the size of the data it points to (i.e., the next 
node in the linked list), only the size of the pointer itself.




Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: