I have a doubt that initialization is when we do declaration and assignment both together so when we use initialization list we just do a kind of assignment like msp(99) we have just insert the value we have declare it before. So how it can be initialization.
Regarding Initialization List
Hey @sarthak_singhal see this doubt
if it still doesn’t answers your query let me know. Will help you accordingly.
No actually my doubt is that when we do:- int a (it is called declaration) and if do a = 5 (this is called assignment) and if we do int a = 5(this is called initialization). So refering to the photo that I have attached we write const int msp once and than with function we use initializer list we write this Car() : msp(99) so it looks like an assignment because we are just giving a value and we have declared variable earlier. So my doubt is that how we have initialize the variable we assigned it
This is Initializer List, Reason for initializing the const data member in initializer list is because no memory is allocated separately for const data member, it is folded in the symbol table due to which we need to initialize it in the initializer list.
It might look as an assignment, but we are explicitly assigning the const data members.
At the time stamp of 2:00 to 2:35 sir said that memory for the variables is allocated just before entering the body of constructor so we initialize the variables. If yes than how the memory is allocated for the variables (like int ,char) in case we don’t use initializer.
can you mention it with some example that’s coming in your mind. Then it would be easy to explain.
i watched the video again and what I understand that ki variables ke liye memory constructor ki body shuru hone se pahle occupy hogi or humne uss time pe jo constant variable hai uski value rakh di. Lekin yaha jo doubt aata hai vo ye ki jab humne variables ko pahle declare kar liya orr fir humne uski value baad m di toh vo initialization kaise hua vo toh assignment hua na??
Please wait for some time, i have asked this doubt from mentor. Will get back to you on this soon.
But as far as i think is that const member memory gets allocated before you construct the object, before entering the initializer list. Now you can only initialize the variable in the intializer list by giving the value as shown in the video.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
