when is memory allocated for static variable in c++
Static variable In general, static memory allocation is the allocation of memory at compile time, before the associated program is executed, unlike dynamic memory allocation or automatic memory allocation where memory is allocated as required at run time.[1]
C++ classes Instances of a class data type are known as objects and can contain member variables, constants, member functions, and overloaded operators defined by the programmer.
Resource acquisition is initialization Both Clang and GNU Compiler Collection implement a non-standard extension to the C language to support RAII: the "cleanup" variable attribute.[12] The following macro annotates a variable with a given destructor function that it will call when the variable goes out of scope:
Include directive In C and C++, the #include preprocessor directive causes the compiler to replace that line with the entire text of the contents of the named source file (if included in quotes: "") or named header (if included in angle brackets: <>);[1] note that a header need not be a source file.[2] Inclusion continues recursively on these included contents, up to an implementation-defined nesting limit. Headers need not have names corresponding to files: in C++ standard headers are typically identified with words, like "vector", hence #include <vector> while in C standard headers have identifiers in the form of filenames with a ".h" extension, as in #include <stdio.h>. A "source file" can be any file, with a name of any form, but is most commonly named with a ".h" extension and called a "header file" (sometimes ".hpp" or ".hh" to distinguish C++ headers), though files with .c, .cc, and .cpp extensions may also be included (particularly in the Single Compilation Unit technique), and sometimes other extensions are used.