what is the order of initialization for data?
Answer Posted / kasi
1) Brief details on initialization:
To perform true initialization (not assignments) for a
class data member, C++ provides extened syntax for
constructor function.
Syntax:
class A
{
int ssn;
double sal;
public:
A(int j,double k):sal(k),ssn(j) //initialization
{
//assignement
}
}
Therefore constructor function has 2 parts they are
- initialization
- Assignment
Note - initialization will be excuted first and then
assignment
2) When is the initialization list mandatory?
- If the instance variable is constant
- If the class contains reference variable
3) coming to the posted question: order of member
initialization will be done in 2 ways by the compiler.
A) Declaration order
B) The order of members in the intialization list.
For the above example ssn is initialized first then sal.
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What is the object serialization?
how to explain our contribution in the project?
Explain explicit container.
What are the extraction and insertion operators in c++? Explain with examples.
If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3
Define namespace in c++?
How do I download c++?
What is the array and initializing arrays in c++?
What is the purpose of templates in c++?
What are stacks?
What is virtual methods?
What is an iterator class in c++?
Write about the access privileges in c++ and also mention about its default access level?
How delete [] is different from delete?
Explain dangling pointer.