I dont know if you will read this in 2024, but this question alone cleared SO MANY concepts for me and helped me in many interviews, I wasasked this question in an HFT ( he loved the fact that I answered basic details), and LOL I learnt it from here !! Thanks to him and you.
Thank you so much for made this video. I got the same question while giving interview very recently. But, I seen this video very long time back. Luckily, I'm able to come up with proper approach because of you guys made the concept crystal clear and your C++ series and design pattern videos helped me a lot. Fortunately, I got an offer from that company as well. Thanks again for your contribution to the community!!!
Excellent video for C++ developers. Thanks to both. Back in the 20's, this question was one of the most frequently asked questions in an interview. I faced it between 2012 and 2015
Very comprehensive 👍 Couple of points I would like to bring to your notice. 1) Calling overload > operator for strings constructed using default constructor is problematic here as resource pointer is initialized with nullptr. 2) Move constructor will not have const rvalue reference as we are resetting the values here.
One thing that we should always remember for production quality code , is to check any pointer for null before using strcpy etc as it will crash the program, this code will not pass a code review. Kudos for bringing in so much valuable content though.
Hi Keerti, First of all good video. Secondly, some noticeable points: 1) The defined >> overloading will not work properly. 2) The Move Assignment should have been implemented as it would would have cleared few points like while making statements : Ex- S2 = std::move(S1) ; Copy assignment and Move Assignment both would have been a viable option. Hence compiler will report an ambiguity. 3) As others have already mentioned, use of const in Move Constructor. But happens :) 4) A great question could also have been an explanation on how compiler knows how many bytes to delete when calling delete[] . But above all, Great Work and Really Helpful for all. Thanks to Amit too.
Why is this series ended with only 2 episodes. I would like to see more of the #C++ episodes and C++ mock interviews as well. Thanks for the content Keerthi.
Perfect...spot on....looking for something like this only! Would be really helpful if you could do similar kind of interview for C++ Multithreading and Process synchronisation. Really appreciate your efforts Kirti ✌️
Two small remarks to this great video: 1. In 25:10 the length() member function really should be const, otherwise you will restrict it to only non-const objects. I personally would consider it a mistake and would try to steer the person into thinking about it and correcting it by himself. That would show whether this was just an oversight, or if he is not aware of this at all. 2. Making a class like this and leaving destructor to the very end is also not very good. You really should write one immediately when you write the first constructor that calls new. This is just a tip what to avoid not only in interviews, but also in everyday programming :)
Thanks Keerti and Amit with such an amazing video, the very same yet with a twist i was asked to implement grep function which we used to have in unix or linux that too with use of multi-threading at Nokia for Sr. Software Er. position.
Nice video . If you refer this vide your half of interview is already clear !! One small correction in Constructor and in assignment operator this->res[len] = '\0'; //null termination character This must needed I think
Thank you for this wonderful video. I had a C++ based Interview round few days back, and I wish that I had gone through it once. The Interviewer confused me at some concepts which got cleared through this video and forever :p. However, I was shortlisted :). But I'll make sure to go through this video every time I have a C++ Interview. Love your content. Thank you ❤
Amazing video. Can you please use a code sharing platform such as leetcode interview or any other platform that formats the code automatically instead of doc editors. That would be helpful to the interviewee as well as to the viewers. Thanks.
Very nice explanation... I found one bug, that is before inserting the value we should assign some memory to the pointer, else it will lead to segmentation fault. Please take it positively. Thanks you guys...
Good one Keerthi !. But few issues in this .1. Inside string one arg constructor you are using strcpy and copying ch . What if ch dangling and tempting to copy ch to res will be issue .2.also strcpy is not safe function can cause buffer overflow. 3. Towards the end he did made pointer as null and after that he tried to initialize a member var as 0 :) may be overdoing in interview . Overall good job explaining move ctr . You can also ask him what will happen if you execute move constructor before assignment operator 😊
The video is great with great details to concepts. One suggestion would be to not add the suggestion box exactly where he is typing ex: 24:58 . It really blocks the view and prevents us from following what is being explained. This happened many times during the video.
While righting the move copy constructor you used const reference as parameter and then assigned null values to res and length. That would not be allowed I guess as you trying to change values of a const reference. Any comments will that work?
have you heard of c++ builder? it allows you to do rad development for windows and numerous other o/ss and new CPUs. it's native compiler and the compiler is based on CLANG.
Wow di amazing content. I really like the way you explain. You are an OP and my ideal. Di I request you to make similar kind of video on oops concept too.(mush in need) concept tho paad liya, but interview ready hai ya nhi ya nhi pata. Di you are our ideal please keep posting such type of content much in need. English jaad acchi nhi hai.. esliye koi flowery statment nhi likh payi.. plz ignore...
For str1 we don’t really need to use any initializer list or initialising vars in body. Just give default values to private members and your compiler will be happy :)
Hi Keerti, in overloading operator "istream& operator>>", the argument must be ONLY a String object by reference, it should not be constant. Also in the move constructor, it should not be (const String&& str) but only (String&& str). What do you think? Thanks
Hi Keerti Thanks for such a nice and detailed video. It really helps, we don't get such material easily on net. It will helpful if you create such more videos on C++. Thank you again.
Hi Keerthi, did you get selected for Atlassian with C++? Their JD always looks for Java spring for the backend. How to get into it as a C++ backend engineer?
@@tech_wizard9315 it's quite important concept, not that difficult imo if you have an understanding of copy constructors and copy assignable . Good Luck
@@KeertiPurswani str is another object and str.len, str.res are private. We are using these inside constructor of class. May be I'll code it to get some clarity. Thanks for making this video it really gave some sparks to my brain. It has been years since I have used a friend or operator overloading.
Can you assign a const rvalue String&& str to nullptr?? passed inside the move constructor?... even when you do it some how making it non const would you be able assign 0 to the str.len after assigning str to nullptr?? ..... at 40 to 45 minutes in the video.... not sure if its a mistake or if I am wrong... I appreciate the great content though.
I have a doubt with respect to the implementation. Why is it that we are trying to use the string functions like strlen and strcpy when we are trying to mimic the string class itself? It looks like monkey patching to me. I would really love if anyone could clarify this.
Can you please complete the design pattern series. It's been quite a time u have not uploaded any video on it. Btw really find this video helpful. Thankyou 😊
I was planning to finish in jan but something came up. Left Intuit also. Need another 10-15 days. Everything is ready. Just need to find time to record. Sorry for the inconvenience caused but I promise, I will finish it for sure!
If we use move constructor, then the original objec tis deleted and the same vakue assigned to new object. So my question is if we are using the same value for the object then why can’t we use the old object?
I have a question here. I hope you won't mind. When an interviewer says implement "your" string class, doesn't that mean that we have to implement our actual class? Like for the 'length' function we have to do the parsing and find out the length instead of using a predefined function, for copying we have to copy character by character instead of using strcpy. I mean it doesn't make sense for me to use predefined functions in our functions and call it "our class". @Keerti Purswani
If you know how much time costly a for loop or any loop is for copying individual characters ... you would not say that... yes we can use user defined implementations for them instead of standard lib functions... thats our choice to use the best in that scenario...
At what yoe will you expected to solve such a question in the interview? Like straight up be asked to impliment a string class itself.. I thought I had a good grasp on cpp but now i feel very demotivated lol