1

The size of function is used to find the size of any variable, For instance, if we pass char,int and double it returns 1,4 and 8 respectively . In initializing a class object having all these parameters defined in that in different sequence have different size of object. for example if we define

class X{
double A;
int B;
char C;
}
//The size of(object_class_X)will be[16bytes],by changing sequence to
class X{
char A;
int B;
double C;
}
//The size of(object_class_X)will be[24bytes]

Why the sequence of variable matter in memory allocation? And how its going to be 16 and 24 for above sequence?

john
  • 79
  • 7

0 Answers0