static

Explanation of the "static" keyword in C++:

  1. Static Variables:
  2. When "static" is used with a variable inside a function, it retains its value between function calls.
  3. The variable is initialized only once, and its value is preserved throughout the program's execution.

  4. Static Functions:

  5. When "static" is used with a function, it restricts the function's scope to the file it is defined in.
  6. This means the function cannot be called from other files using the extern keyword.

  7. Static Class Members:

  8. When "static" is used with class members (variables or functions), it signifies that the member belongs to the class itself, rather than to individual objects of the class.
  9. Static class members are shared by all objects of the class.

  10. Static Local Variables:

  11. When "static" is used with a local variable inside a function, it retains its value between function calls, similar to a static variable inside a function.
  12. The variable is initialized only once, and its value is preserved throughout the program's execution.