Member Functions
Member function/operations/implementation details help us to perform operations on the data elements of the class.
“These help us to specify what and how the operation is performed.”
The definitions of the member functions can be given either
* Outside the class definition
* Inside the class definition
The member functions of the class are invoked/called by the objects of the class using. (dot) operator.
Example:
student s;
s.read();
s.show();
Size of the class is the sum of the sizes of all the data elements. Size of the class can be calculated using the operator “sizeof()”.
sizeof() : helps us to find the size of a data type or a variable or an object.
Example :
int a;
cout<<sizeof(int); o/p: 2
cout<<sizeof(a); o/p: 2
Note:
(1). Size of “int” in turboc3 is 2 bytes.
(2). Size of “int” in code blocks is 4 bytes
float x;
cout<<sizeof(float); o/p: 4
cout<<sizeof(x); o/p: 4
student s;
cout<<sizeof(student); o/p 26 (2+20+4)
(in code blocks 28 bytes)(4+20+4)
cout<<sizeof(s); o/p 26 (2+20+4)
(in code blocks 28 bytes)(4+20+4)
Note: The size of a class with no data element is 1 byte.
class employee
{
};
employee e;
cout<<sizeof(employee); o/p 1
cout<<si zeof(e); o/p 1