devxlogo

Static Initialization and Dynamic Initialization

Static Initialization and Dynamic Initialization

C++ distinguishes between two initialization types for objects with static storage duration (global objects are an example of objects having static storage). Static initialization consists of either zero-initialization or initialization with a constant expression; any other initialization is dynamic initialization. These two types roughly correspond to compile-time initialization and runtime initialization. For example:

 int x = func();int main(){}

The global variable x has static storage. Therefore, it’s initialized to 0 at the static initialization phase (this is the default value of objects with static duration). The subsequent dynamic initialization phase initializes x with the value returned from the function func(). Note that func() must be invoked for that purpose

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist