• Register
632 points
7 1
Overview static
Static keyword in c++
Static object 
Static example program 
Article Tags 



Static Keyword in C++

Today we will learn about static in C ++, what is static in C ++ and what work they perform. In fact, static are variables. This type of variable is used only on special occasions.  It usually happens that when a function is called, it introduces it into the local variable memory to perform its functions. Similarly, when the function does its job, the control is returned to the main as well as the memory.  Eliminates all local variables in. However, sometimes we want a variable of a function to remain in memory, including its quantity, even after the function is exhausted. For this, while introducing this function, type it.  Let's write the word Static before. The initial value of these variables automatically becomes 0.

Static Keyword can be used with following:

1.Static variable in functions

2.Static Class Objects

3.Static member Variable in class

4.Static Methods in class



Static part capacities can be utilized to work with static part factors in the class. An object of the class isn't needed to call them.Classes can be made with all static part factors and static capacities. In any case, such classes are basically what could be compared to pronouncing capacities and worldwide factors in an internationally available namespace, and ought to by and large be stayed away from except if you have an especially valid justification to utilize them.I hope after reading this article you will be able to understand the static variable in C++. I would like to have feedback from my kodlog site. Please post your feedback, question, or comments about this article.

Static Objects:

Static object is an object that persists from the time it's constructed until the end of the program. Stack and heap objects are excluded. Even global objects, objects at namespace scope, objects declared static inside classes||functions, & objects declared at file scope are included in static objects. Static objects are destroyed when the program stops running.

syntax of static keyword in C++ language,

static datatype variable_name = value; // Static variable
static return_type function_name { // Static functions ... }
Let us look at an example program.

// C++ program to demonstrate  
// the use of static Static  
// variables in a Function 
#include <iostream> 
#include <string> 

using namespace std; 


void demo() 

    // static variable 

    static int count = 0; 

    cout << count << " "; 


    // value is updated and 

    // will be carried to next 

    // function calls 



int main() 

    for (int i=0; i<5; i++)     


    return 0; 


Article Tags 

C#|Python |Python 3|pycharm |html|java|JavaScript |cpp|code|rubi|Network | Google |html5 |php|bootstrap |string |Microsoft |variable |syntax |Coders |Codinglove|
Xml|game| net| list | loop | integer |float | string | double |


Such a nice explanation you had explained in this article... Very useful information... Keep sharing more...
Such a great article for C++