What are Static data members and Static functions in C++?

Static Data: Static data is the one which is stored only once in the memory for the entire class and all the objects of the class uses the same static data. Basically static data relates to the entire class and all the objects of that class share that data. We can make the data of the class as static by using the static keyword.
Syntax for declaring static data member:
Class classname
{
Static data_type data_member;
};

Static function: Static functions are those functions which have the access to only static data of the class within it and not the non-static data. A static function is declared using static keyword along with the function declaration. We can access the Static functions by the class name rather than by objects.

Syntax for declaring Static function:
Class classname
{
Static return_type function_name ();
};

More Questions

Leave a Reply

Word Verfication * Time limit is exhausted. Please reload CAPTCHA.