In C++ the memory is created only when we declare the object(s) for the respective class(s).
So when we make any member function as static inside the class, we are able to access that member function directly by the class name, without creating any object of the class.
Then how the memory is allocated in this condition without any object.
Example program:
#include<iostream>
using namespace std;
class sample
{
static int a,b;
public:
static void read()
{
cout<<"Enter integers:- ";
cin>>a>>b;
cout<<"a= "<<a<<endl;
cout<<"b= "<<b<<endl;
}
};
int sample::a;
int sample::b;
int main()
{
sample::read(); //Accessing read() with the class name
return 0;
}