HomeОбразованиеRelated VideosMore From: CppNuts

When To Use Reference Over Pointer and Vice Versa In C++

49 ratings | 2454 views
In this video i have tried to explain that how many places we can use reference over pointer and achieve best performance and good coding style. Difference Between Reference And Pointers In C++ : https://youtu.be/h2aLDuwJuok -CppNuts #CppNuts #C++InterviewQuestionsAndAnswers #MasterInC++ #HowToMasterC++Programming #HowToCrackC++Interview #CrackC++Interview #LearnC++Programming
Html code for embedding videos on your blog
Text Comments (14)
Anurag Dogra (2 months ago)
Great video with infos. Keep it up.
CppNuts (2 months ago)
Thanks for appropriation!
PRAMOD KUMAR KAR (5 months ago)
Sooper !!!!
CppNuts (5 months ago)
Thanks man!!
NITHYA NARAYAN (7 months ago)
Why its an error to use pointer in copy constructor?
CppNuts (28 days ago)
Guys, we can use pointer copy constructor. Try and let me know if there is some problem.
sajit k (28 days ago)
+NITHYA NARAYAN I am also searching answer for the same question for looooong, what I see is, reference is safe..it ensure the data is valid..pointer doesnt ensure this..it can be NULL or invalid..
NITHYA NARAYAN (7 months ago)
My question is why we don't use pointer in copy constructor instead of reference?
CppNuts (7 months ago)
I don't seeany problem in this code can you tell me where the actual problem is?
NITHYA NARAYAN (7 months ago)
#include <iostream> #include<thread> using namespace std; class base{ int x; public: base(int x1):x(x1){ ; } base(const base &o){ x=o.x; } void print(){ cout << x <<endl; } }; int main () { base b1(10); base b2=b1; b1.print(); b2.print(); }
Peterolen (10 months ago)
These are good advice. And it doesn't matter how the objects are stored. If you have a pointer or smart pointer to some object you can still pass it by reference by first using the dereference operator.
Ady2xp (11 months ago)
Good video as always! Thank you and keep the good job!
CppNuts (11 months ago)
+Ady2xp thanks dude.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.