Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Is map ordered c++?

1096


What is object in c++ wikipedia?

1001


Which is not an ANSII C++ function a) sin() b) tmpnam() c) kbhit()

1535


What is binary search in c++?

1031


Incase of a function declaration, what is extern means?

972


Where is atoi defined?

1142


Explain polymorphism?

1078


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

1325


What is tellg () in c++?

1308


How do I use arrays in c++?

1002


How is new() different from malloc()?

1128


What is encapsulation in C++? Give an example.

1100


What do you mean by persistent and non persistent objects?

1435


Can we run c program in turbo c++?

1082


Is java a c++?

1042