2
Reply

how memory is allocated, when an instance is created for a class.for example when a class is instantiated two times,does every object has its own memory block?

    The memory allocation to the class is very interesting process consider the following class


    class MyClass
    {
     int num;
    char ch[15];
    public:
    void getNumChar();
    }

    While allocating the memory to above class
    2 byte for num
    15 byte for ch
    In such a way 17 bytes for class

    If you create 2 objects of the class then 34 bytes will be allocated for the class. The memory allocation is depends on the how many times you are creating the object of that class and the data types of attribute.

    Yes every object has its own separate memory block....