
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What do you mean by a dynamic initialization of variables?
Dynamic initialization of object refers to initializing the objects at run time i.e. the initial value of an object is to be provided during run time. Dynamic initialization can be achieved using constructors and passing parameters values to the constructors. This type of initialization is required to initialize the class variables during run time.
Why we need the dynamic initialization?
Dynamic initialization of objects is needed as
It utilizes memory efficiently.
Various initialization formats can be provided using overloaded constructors.
It has the flexibility of using different formats of data at run time considering the situation.
Example Code
#include <iostream> using namespace std; class simple_interest { float principle , time, rate ,interest; public: simple_interest (float a, float b, float c) { principle = a; time =b; rate = c; } void display ( ) { interest =(principle* rate* time)/100; cout<<"interest ="<<interest ; } }; int main() { float p,r,t; cout<<"principle amount, time and rate"<<endl; cout<<"2000 7.5 2"<<endl; simple_interest s1(2000,7.5,2);//dynamic initialization s1.display(); return 1; }
Output
Enter principle amount ,rate and time 2000 7.5 2 Interest =300
- Related Articles
- What do you mean by Dynamic memory allocation in C programming?
- What do you mean by Scope of variables inside MySQL stored procedure?
- What do you mean by starch?
- What do you mean by adolescence?
- What do you mean by heat?
- What do you mean by tissue?
- What do you mean by environment?
- What do you mean by Garbage?
- What do you mean by Propagation?
- What do you mean by Silk?
- What do you mean by Sex?
- What do you mean by disease?
- What do you mean by Nutrients?
- What do you mean by Obesity?
- What do you mean by Ruminants?

Advertisements