Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions