Question: You need to write a main function in it which will calculate size of each struct. Then you need to find efficient way to place

You need to write a main function in it which will calculate size of each struct.

Then you need to find efficient way to place the struct elements so that the whole struct takes less space in memory.

For Example:

struct {

char b;

int i;

char c;};

The above struct takes 12 bytes in the memory. After rearranging the above struct we get the following:

struct{

char b;

char c;

int i;};

The struct after rearrangement takes only 8 bytes in the memory. So by changing the arrangement of the structs elements we can use memory more efficiently.

----------------------------------------------------------------------------

#include  struct p{ int id1; char name; int id2; char c; float percentage; }; struct q{ char first[10]; char middle_initial; char last[10]; double salary; int numinhousehold; }; struct r{ char b; int a[2]; int i; char c; int *p; }; struct linked{ int d; struct linked *next; struct linked *prev; char c; }; struct mat{ int a[4][3]; char b[10]; double d; int c[3][3]; }; 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!