 Hello friends. I am Sanjay Gupta. In this video, I am going to demonstrate you how you can use static data and static member functions in C++. Before starting, you can note my information. You can follow or subscribe my YouTube channel that is sanjaygupta underscore tech school. You can download my Android app that is Techimage which is available on Google Play. Now, coming on to the topic. First, I have included a header file that is iostream. Then STD namespace is used. Now name of class is test, which is having two attributes. One is count, which is static. So here this count is static data and this X is non-static data. So when you declare any variable as static compiler automatically creates a memory location for this static variable, whether you create any object or not. So you can see in this demonstration, I have not created any object. Still this function will display the value of count, but this X is a non-static data. So it will be having a memory when its object will be created. Then a constructor is defined, which is receiving an argument in A. Then A is assigned into X and then count is incremented. Then show function, which is displaying value of X and then show count function, which is displaying value of count. Notice that this function is declared as static. So this is a static member function. So static member function is also a spatial member function, which can be called through name of class and without creation of any object. So you can see I have called show count function with the help of class name and I have not created any object. Before main function, I have initialized static variable by zero. So this is the syntax of initializing static variable. Now first time executing this code, you can see the output count equals to zero is displayed. So I have not created any object. So count is having a memory location. It is initialized by zero and it is displayed using static member function and that static member function is called through name of class and scope resolution operator. Now I am creating first object of this class that is T1 and I am passing five inside it. So with this statement constructor will be executed. So T1 will be having a memory block where only for X memory will be allocated, not for count. So X will be initialized by five and this count variable will be incremented by one. So now you have to notice that if I am creating more than one objects, so this count variable that is static variable will be shared by all the objects. So I am going to demonstrate you this. Now I am calling T1 dot show function and then T1 dot show count. So you can see the difference here. Show count is called through class name and here I am calling it with object name. You can also write this statement here. So you can call this function through class name if you have not created any object and if you have created an object, then you can call it through the object also. So first time executing this, you can see the output count is zero, then value is five and then count has incremented by one. Now I am creating one more object. This time you can see I am calling show count through class name. So I can call it through object as well as through class name and I have created T2 another object. So here constructor will be called. A will be assigned into X and count will be incremented by one. So here count will become two because previously it was one. So now we can see the output. First count is zero, then value through show function is displayed five, then through show count one is displayed. Then again, second objects value 10 is displayed and you can see now count is two. So friends, if you want to share a single attribute of the class with multiple objects, then you can declare that variable as static. And that static variable will be managed by the static function and static function can be called through name of class or through object of the class. And these static variable and static function are gathered memory without creation of any object. So if you have not created any object, then also you can access static variable as well as static function. So this is all about static data and static member functions which are available in C++. I hope you have understood the concept. If you want to watch more programming related videos, you can follow or subscribe my YouTube channel that is sanjaygupta underscore tech school. Thank you for watching this video.