Considereing int take 2 bytes of memory. What is size of memory allocated for ob in the below program.the size of memory allocated for object of class class my_class { int x; int y; public: void add(int k); void display(); }; my_class ob;
-
4 bytes
-
6 bytes
-
8 bytes
-
12 bytes
A
Correct answer
Explanation
The class my_class contains two int data members (x and y). Given that int occupies 2 bytes, the total size is 2 + 2 = 4 bytes. Member functions (add, display) do not contribute to object size as they are stored once in the code segment, not per object instance. Options B, C, and D incorrectly add extra bytes for member functions or padding.