Skip to main content
added 12 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int const a = 10 ; //static initialization //10 is known at compile time. Its 10! int const b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int const a = 10 ; //static initialization //10 is known at compile time. Its 10! int const b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

added 11 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 )  return -1; //indicates input error else if ( n == 0 ) return 1; else  return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 )  return -1; //indicates input error else if ( n == 0 ) return 1; else  return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

added 199 characters in body; edited body; added 1 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically initialized-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then at runtime, it's dynamically initialized with the value function factorial().

Dynamic initialization is that in which initialization value isn't known at compile-time. It's computed at runtime to initialize the variable.

Example,

int factorial(int n) { if ( n < 0 ) return -1; //indicates input error else if ( n == 0 ) return 1; else return n * factorial(n-1); } int a = 10 ; //static initialization //10 is known at compile time. Its 10! int b = factorial(8); //dynamic initialization //factorial(8) isn't known at compile time, //rather it's computed at runtime. 

That is, static-initialization usually involves constant-expression (which is known at compile-time), while dynamic-initialization involves non-constant expression.

static int c;//this is also static initialization (with zero)! 

§3.6.2/1 from the C++ Standard (2003) says,

Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.

So there are two kind of initializations:

  • Static initialization : Its either zero-initialization or initialization with a constant expression
  • Any other initialization is dynamic initialization.

Also note that the same variable can be dynamically-initialized after it has been statically-initialized. For example, see this code:

int d = factorial(8); int main() { } 

Since d is a global variable, it has static storage. That means, according to §3.6.2.1 it's initialized to 0 at the static-initialization phase which occurs before any other initialization takes place. Then later, at runtime, it's dynamically-initialized with the value returned from the function factorial().

That means, global objects can be initialized twice: once by static initialization (which is zero-initialization) and later, at runtime, they can be dynamically-initialized.

deleted 2 characters in body
Source Link
Matthieu M.
  • 303.2k
  • 58
  • 495
  • 754
Loading
added 59 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867
Loading
added 110 characters in body; added 320 characters in body; added 12 characters in body; added 2 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867
Loading
added 191 characters in body; added 10 characters in body; added 69 characters in body; added 206 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867
Loading
added 59 characters in body; added 167 characters in body; added 46 characters in body
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867
Loading
Source Link
Sarfaraz Nawaz
  • 363.4k
  • 121
  • 682
  • 867
Loading