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


Please Help Members By Posting Answers For Below Questions

What is the object serialization?

609


how to explain our contribution in the project?

3067


Explain explicit container.

629


What are the extraction and insertion operators in c++? Explain with examples.

631


If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3

824






Define namespace in c++?

643


How do I download c++?

564


What is the array and initializing arrays in c++?

500


What is the purpose of templates in c++?

559


What are stacks?

603


What is virtual methods?

651


What is an iterator class in c++?

584


Write about the access privileges in c++ and also mention about its default access level?

606


How delete [] is different from delete?

585


Explain dangling pointer.

672