this Pointer in C++ | C++ Tutorials for Beginners #53

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 285

  • @sauravsharma4615
    @sauravsharma4615 4 роки тому +182

    Harry : The Code Machine

  • @anishsingh9043
    @anishsingh9043 Рік тому +118

    If any one couldnt understand, follow this. Give a thought. I was too stuckee here and had to watch the same video couple of times.
    If I am wrong,correct me.
    This pointer : (this->)
    Like we saw in the previous video, that with the help of pointers we can point an object and use it.
    So here instead of creating a pointer explicitly. We can implicitly do with the help of inbuilt pointer known as this pointer.
    Syntax : as in previous video we used to use
    (*ptr).setData(variables);
    Which modified into
    ptr->setData(variables);
    (-> also known as arrow operator which derefernces and sends the value of the pointer to the class for the object we created).
    So here we use `this instead of ptr (both this and ptr are pointers. `this is inbuilt, while the ptr is the name we have given to a pointer which we made).
    Use of this pointer :
    1) When the name of local variable (variables defined in the assignment of the function) and the instance variable or
    the variables which we created inside the class.
    Inshort local variable and instance variable when have the same name, then there is use of this pointer.
    • Why the need of to use?
    1) Because the compiler will give more priority to local parameters than the global parameters.
    2) It couldnt distinguish and, the value will be couldn't assigned to the variable of the object we defined. And due to non assignment of the variable of the object. The compiler will give our variable of the object, a garbage/random value.
    • How we use?
    - We use in this way
    Class Practice{
    int a;
    public:
    void setData(int a){
    Wrong :
    a = a;
    [The first a we used for is the object, and the second we use for is the local variable. This is thing which we know, but how will compiler know? So it will get confused. And take both the a as the local variables).
    Right :
    this->a=a;
    [With the help of this inbuilt pointer, the compiler gets to know that, woah this person defined the first a as the variable of the object (which object, the object which we currently defining and using) and the second variable as the local variable. Now we have successfully set the value of the variable of the current object and now it won't have a garbage value].
    So i hope the first use of this pointer is clear, that here our this pointer, helped us in telling our compiler that this a is for our object and not for the function as a local parameter.
    }
    };
    2) When we need to chain the member functions of the class for the same object
    Also known as - to return reference to the calling object.
    • Why we use?
    - So that we can chain functions. And send the reference.
    • How we use or implementation?
    -
    class Practice{
    int a;
    public:
    Practice & setData(int a){
    this->a=a;
    //Value of a is set of the member function
    //Now to chain the function or send the reference
    return *this;
    //Here the returning helps to send us the same object for further to be used by the chains of function.
    }
    Syntax //
    Class_Name & Function_name (local variables) {
    code;
    }
    };

    • @anushka.043
      @anushka.043 Рік тому +1

      👍👍

    • @T_tintin
      @T_tintin Рік тому +7

      Thank you so much for the explanation. It helped me a lot. But still I am confused in the returning the reference part.

    • @satender1616
      @satender1616 Рік тому

      When we return a reference of the object we can also change the value of data member by member access operator.

    • @chiraggamer3047
      @chiraggamer3047 Рік тому

      you don't know how much time you saved,bro thank you

    • @sergion_brayen
      @sergion_brayen Рік тому +1

      *thank you so much brother for the wonderful explanation , you deserve a 💝

  • @bubbles_8
    @bubbles_8 4 місяці тому +4

    I want to tell you that many programming students from Pakistan love your videos as they are really helpful. Even our professors tell us to learn programming from your channel. I really find your videos amazing. Thanks once again 😊

    • @MdAyan-l6f
      @MdAyan-l6f 2 місяці тому

      really bro nice to listen it

  • @mukkecitizen
    @mukkecitizen 4 роки тому +33

    The best programming channel

  • @mauhidusmani7212
    @mauhidusmani7212 3 роки тому +73

    i watched this video more than 10 times ,i thought i should skip it,
    but once i got the logic and reason behind i just amazed how easy it was , love the way you teach.
    keep doing great.

    • @AshishKumar-lr9vd
      @AshishKumar-lr9vd 3 роки тому +2

      I also find hard in 1st attempt but after 2nd watch , i found it,s so easy and brilliant logic.

    • @prateeklikhar1893
      @prateeklikhar1893 3 роки тому

      can anyone help me with the referce variable thing like &A ,what was that didnt understand this

    • @sanyamjain4459
      @sanyamjain4459 3 роки тому +1

      @@prateeklikhar1893 same here

    • @JustListen41473
      @JustListen41473 2 роки тому +1

      @@prateeklikhar1893 lecture 7 dekho reference variables ke liye

    • @prateeklikhar1893
      @prateeklikhar1893 2 роки тому

      @@JustListen41473 harrry bhaiya ekdum clear explain nhi krpaye
      Mujhe full clarity babbar bhaiya ki refernce variable video se hui
      Highly suggested.

  • @sumanparajuli229
    @sumanparajuli229 4 роки тому +37

    C++ is popular for developing different games or in gaming engines.... So can, you make a video on this thing in upcoming tutorial....it will give us a broad concept and idea to us...

    • @saitej4750
      @saitej4750 3 роки тому +3

      How can we learn graphical programming in c++

    • @shardaojha7558
      @shardaojha7558 Рік тому

      Find a tutorial so you can learn "sfml" header file. It will help you to create 2d games

  • @lokeshrewar
    @lokeshrewar 4 роки тому +8

    Keep it up Herry Bhai....👍👍
    ..
    ..
    ..
    Best channel for programming

  • @pal228
    @pal228 4 роки тому +10

    Thanks for providing this amazing coding tutorials for free in hindi , thanks Harry bhai from bottom of my heart , carry on this good job, god bless you.....🙏🙏🙏😊😊

  • @bhaskarverma8943
    @bhaskarverma8943 2 роки тому +3

    You teach better and easy to understand than my college teachers such a good teacher have never seen before

  • @vaibhavmulak7267
    @vaibhavmulak7267 4 роки тому +15

    Sir ji ek 💓 Dil to banta hai

  • @adityapradhan8474
    @adityapradhan8474 11 місяців тому +1

    Thank you so much harry bhai
    Polymorphism aur file handling bacha hai fir meri c++ complete

  • @engineerbhai7642
    @engineerbhai7642 4 роки тому +1

    Best channel in you tube for programming. Excellent teacher.

  • @Sanki444MiniMilitiaKing
    @Sanki444MiniMilitiaKing 2 роки тому +1

    Your the best teacher in the world...

  • @adarshkhatri993
    @adarshkhatri993 3 роки тому +9

    Bro..
    You don't know that you are doing such a 💓GREAT WORK💓 for us.

    • @satyamsingh3
      @satyamsingh3 3 роки тому

      plz reply return obj what does it mean by?

    • @adarshkhatri993
      @adarshkhatri993 3 роки тому

      @@satyamsingh3 what??
      I didn't get your point?

  • @T.Akshay_Pratap_Singh
    @T.Akshay_Pratap_Singh Рік тому +1

    #include
    using namespace std;
    class A
    {
    int a;
    public:
    void setData(int a)
    {
    this->a = a;
    }
    void getData(void)
    {
    cout

  • @Sanki444MiniMilitiaKing
    @Sanki444MiniMilitiaKing 2 роки тому +1

    Harry bhai aapke brain me total language ke compiler fit kiye he..♥️😉

  • @trueknowledge2065
    @trueknowledge2065 4 роки тому +9

    HARRY BHAI ARTIFICIAL INTELLIGENCE WITH PYTHON PAR EK SERIES BANAO NA PLEASE........
    JO JO AGREE KARTA HAI LIKE KARE
    YAHAN

  • @RaviYadav-ru1nu
    @RaviYadav-ru1nu 4 роки тому +3

    Love you Harry Bhai !!!
    Your class is always;
    Best & interesting class ever !!! :)

  • @shubhamhire9390
    @shubhamhire9390 4 роки тому +1

    Thanks harry bhaiya ek baar me samjh nhi aya tha but phir se dekhne pe Samjh aa gya 😃

  • @anshulpatil7525
    @anshulpatil7525 4 місяці тому

    Thank you Harry Sir for explaining the concept very clearly!

  • @anshrastogi3756
    @anshrastogi3756 4 роки тому +6

    Bhaiya ish course ko advance tak le kr jaana or please data structures and algorithms bhi complete kra dena c++ se... Or Advanced level k projects bhihi btadena c++ k for job opportunities in big tech giants k liye..
    And thank you so much bhaiya for all these courses...❤️❤️

    • @satyamsingh3
      @satyamsingh3 3 роки тому

      plz reply return obj what does it mean by?

  • @shuvendudas3404
    @shuvendudas3404 3 роки тому +3

    I love this course seriously

  • @ishwahijab212
    @ishwahijab212 4 роки тому +16

    sir plz upload videos on polymorphism and operator overloading. also.my papers are going to held in august.your lectures are really helpful for me and i really want to complete your series.thanks .

  • @UzairKhan-it9ef
    @UzairKhan-it9ef 4 роки тому +1

    Love your videos from Pakistan bhai ❣️

    • @rn_yadav007
      @rn_yadav007 3 роки тому

      kon si college se ho bro Pakistan me

  • @vijaymala4846
    @vijaymala4846 4 роки тому +2

    Harry bhai !!! Bigfan

  • @vinitsharma4787
    @vinitsharma4787 2 роки тому +1

    harry bhi 8:00
    agar hum & ko nahi lagaye to bhi run kar raha he to kya difference he & lagane se or nahi lagane se
    ---> agar kese or ko pata ho to pls reply me

  • @programmingwithjavascript3579
    @programmingwithjavascript3579 3 роки тому +1

    Best👍 💞 c++ video ever

  • @simar3759
    @simar3759 4 роки тому +2

    Best channel

  • @ishwahijab212
    @ishwahijab212 4 роки тому

    sir you are the best mentor.i acually really wanted someone to teach c++ in VS code. and finally i reached your channel.

  • @kumkumbhagya51
    @kumkumbhagya51 Рік тому

    8:53 haa reference variable waala revise krna padega aaj

  • @FitnessLoverkanpuriya
    @FitnessLoverkanpuriya 2 роки тому

    thanku so much harry sir. i have learnt c++ ,and i learnt all video c++ serial voice

  • @motionfactz9766
    @motionfactz9766 4 роки тому +2

    Best tutorial bhaiya !! Please make tutorial on gsap

  • @apurvasonawane5049
    @apurvasonawane5049 3 роки тому +2

    Thank you so much Harry bhaii!! I have learnt so many things from this playlist 🙌🏻🔥can't thank you enough:)

  • @iuS1294
    @iuS1294 2 роки тому +1

    thank u bhaiya jiii❤❤❤❤❤❤😍😍

  • @prateeksomani9239
    @prateeksomani9239 2 роки тому +33

    I didn't get anything in this video......this comment is only about this video

  • @Voyager_Plays
    @Voyager_Plays 4 роки тому

    mai programming ko hate karta tha par ab maja aarha hai iam planing to make game in cocos studio Thanks @CODEWITHHARRY
    god bless you sir🙏🙏🙏

  • @manojbhakta4942
    @manojbhakta4942 Рік тому +1

    #include
    using namespace std;
    class A{
    int a;
    public:
    void setDataGarbage(int a){
    a=a;

    }
    void setData(int a){
    a=a;
    this-> a=a;
    }
    void getDataGarbage(void){
    cout

  • @excel8280
    @excel8280 3 роки тому +2

    int main(){
    If(harry==codemachine){
    we=futurecoder;
    }
    else{
    we=harry;
    }

  • @AshutoshKumar-fu6qe
    @AshutoshKumar-fu6qe 3 роки тому +5

    this is a very funny keyword, I kept laughing most of the time while watching the video and searching for same people.
    |
    ^

    • @sudarshanmhaisdhune1039
      @sudarshanmhaisdhune1039 3 роки тому

      Mai tera ye comment dekhke hnsa aur teko paagal samza

    • @AshutoshKumar-fu6qe
      @AshutoshKumar-fu6qe 3 роки тому +1

      @@sudarshanmhaisdhune1039 ​ Mujhe achha laga ki apko meri comment dekh ke khusi hui. But aapko mujhe pagal nahi samajhna chahiye tha, chalo samajh hi gaye toh koi baat nahi.

    • @AshutoshKumar-fu6qe
      @AshutoshKumar-fu6qe 3 роки тому +1

      @@sudarshanmhaisdhune1039 By the way, I have made notes of C++. I you want that reply me.

  • @SyedaRida-E-Fatima-mx7vt
    @SyedaRida-E-Fatima-mx7vt 6 місяців тому

    Harry bhi you are absolutely great.love from Pakistan

  • @asbishen
    @asbishen 4 роки тому +3

    Make some unique projects or games by the end of the course.....

  • @abrarahmad3897
    @abrarahmad3897 Рік тому +1

    I have tried to write a code in c++ wherein I have initiated a class called complex: handling the functionalities of the complex numbers. Also, in the setData(), I have taken the input from the user with the same name as that of the class member by making use of the this keywords that prevents the display of any garbage value on the screen as per the following lines of code. Besides, I have attached my code below for any reference and feedback:
    CODE:
    #include
    using namespace std;
    // class complex : handling functionalities of the complex numbers
    class complex
    {
    protected:
    int real, imag;
    public:
    void setData(int real, int imag)
    {
    // using the this keyword to prevent display of garbage values
    this->real = real;
    this->imag = imag;
    }
    void printData(void)
    {
    cout

  • @SahilSharma-dt7qn
    @SahilSharma-dt7qn 2 роки тому +4

    pointer really fucks with your brain

  • @akashpatel-jp4gh
    @akashpatel-jp4gh 2 роки тому

    It's cool "l will see you next time"🤘🤘🤘

  • @mahenderayadavgoradih1822
    @mahenderayadavgoradih1822 4 роки тому +1

    Harry is one of best programer

  • @GauravKumar-ck7rs
    @GauravKumar-ck7rs 4 роки тому +2

    harry Bhai STL kab padhoge....??
    1. Operator overloading
    2.virtual functions
    ??????

  • @infinity_nepal
    @infinity_nepal 4 роки тому +2

    love u harry bro❤️❤️

  • @mr.proghammer2414
    @mr.proghammer2414 4 роки тому +2

    Bhaiya game development with python mei aur bhi videos daalo

  • @manthanbagade6542
    @manthanbagade6542 14 днів тому

    @CodeWithHarry
    A setData(int a){}
    A& setData(int a){}
    Are these 2 same because I am getting the same output when I am using both. Which is more appropiate? According to what I have understood since we are returning a object first one would be more correct.

  • @victorb22622
    @victorb22622 7 місяців тому

    2:21 हैरी को चीजों को कॉम्प्लिकेटेड करने का शौक है।a रखना ही क्यू है ।दोनो हमसक्ल लेकर जाओगे तो लोग कंफ्यूज होंगे ही ,इसमें तो कई पिक्चर बनी हुई है तीन घंटे की।a = a करना ही क्यू? क्लास भी A ,int bhi a और फंक्शन argument भी a।

  • @brijbhushan5193
    @brijbhushan5193 4 роки тому +1

    Please make it as a complete course
    And upload more videos for completing this coursr

  • @SayanNayak
    @SayanNayak 4 роки тому

    The great indian coder ! (Messiah of CSE students )

  • @RashidAli-ip7dx
    @RashidAli-ip7dx 4 роки тому +1

    helpful video harry sir

  • @ajazabbasrizvi3552
    @ajazabbasrizvi3552 4 роки тому +3

    Hi harry hope ur doing well
    First of all i would like to say ur are an awesome instructor
    I have been following ur web development course and ur phenomenal.
    I had a request harry pls upload a complete course on C# not a one video course
    Complete step by step from beginner to advanve level like ur web developemnt.
    I am eagerly waiting for ur response
    Thankyou
    Ajaz

  • @ankitdighe
    @ankitdighe 3 роки тому +2

    8:36 did not understand why .getData() is being invoked along with .setData(4) in the same line i.e line no.19.

    • @ankitpandey-pg1yn
      @ankitpandey-pg1yn 3 роки тому

      Me too

    • @sagnikroy5001
      @sagnikroy5001 3 роки тому +1

      Actually it's in this case "*this" is returning the the class A as an object and it when you write .getData it's point the getData function of the class which referring by this

    • @ankitdighe
      @ankitdighe 3 роки тому +1

      @@sagnikroy5001 thanks👍

    • @sandeepkumartiwari8436
      @sandeepkumartiwari8436 2 роки тому +1

      @@sagnikroy5001 it is compulsory that object name is same as class member name like"a". Please reply me.

    • @SaumyaSharma007
      @SaumyaSharma007 2 роки тому

      @@sandeepkumartiwari8436 nope brother

  • @namansharma8335
    @namansharma8335 4 роки тому

    Harry bhai nice best you tube channel

  • @kumkumbhagya51
    @kumkumbhagya51 Рік тому

    2:41 par ek achi baat thi koi error bhi nhi aaya tha usme

  • @hitendusseja6615
    @hitendusseja6615 4 роки тому +1

    thanks bro, was really confused

  • @aayushjain9729
    @aayushjain9729 4 роки тому +3

    Brother I want to know that will you add more videos on your web development course series? Pls reply bro and thanks for that awesome content👍

  • @MotivationalGoals23
    @MotivationalGoals23 2 роки тому

    very nice🙌🙌 explanation and easy topic

  • @aniketsahi7778
    @aniketsahi7778 6 місяців тому

    🥳🥳🥳 thank you Harry bhai ✌️✌️

  • @ranjusinha7123
    @ranjusinha7123 4 роки тому

    C#. Playlist banao please..bahut hi accha video raha ye wala

  • @abdaihannan7147
    @abdaihannan7147 4 роки тому +1

    Luv u bhai😘

  • @usmanirfan2584
    @usmanirfan2584 4 роки тому +7

    Q : Kia python se ham Android App bana sakte Jan .
    Plz.... Answer

  • @trueknowledge2065
    @trueknowledge2065 4 роки тому +1

    Harry sir 👌👌👌👌👌👌

  • @bhagyesh_knowledgecity
    @bhagyesh_knowledgecity 4 роки тому +1

    Harry Bhai Great Job, Could you please make multi-file C++ code, where some classes defined in another file and calling in main file!

  • @ArmaanKhan-xs3ub
    @ArmaanKhan-xs3ub Рік тому

    Very nice harry bhai ❤

  • @bhaskarverma8943
    @bhaskarverma8943 2 роки тому

    Love From Chandigarh🥰🥰

  • @narendra7636
    @narendra7636 2 роки тому

    Cout

  • @Souparno_Biswas
    @Souparno_Biswas 2 роки тому

    3:16 Apke sath reh reh kar apka theme bhi apki tarah intelligent ho gaya he. Ye error ko point kar raha hai. Notice that both the a have same theme, but when Sir applies the "this->" keyword it changes it's theme.

  • @muhammadareeb1569
    @muhammadareeb1569 2 роки тому

    Thank you, Harry bhai

  • @royfamily9273
    @royfamily9273 2 роки тому

    Thanks Harry Bhaiya

  • @sagarhans6988
    @sagarhans6988 4 роки тому +1

    bro! this is a suggestion to please mention the last vedio on this tutorial or any tutorial in name.

  • @asbishen
    @asbishen 4 роки тому

    Great Work Keep it up 👍💪👌

  • @niteshbovi769
    @niteshbovi769 3 роки тому

    Sir konsa lhs ka baare maine baath kare hai 9:08 maine

  • @thebeatifulnature3142
    @thebeatifulnature3142 4 роки тому +2

    Nice video

  • @simar3759
    @simar3759 4 роки тому +1

    Bhaiya website bnana bhi sikha do for bussiness purposes

  • @HimAnshuGaurKK1120
    @HimAnshuGaurKK1120 10 місяців тому

    Thanku sir❤

  • @artisshhh
    @artisshhh 3 роки тому +2

    I watched all your vides till now and it's really helpful ❤️❤️ thank you so much.
    But I have a request ..can u plz upload a series of data structures and algorithms including some competitive programming stuffs..?
    It will be a great help . Although u have dsa series too ....I aware of that
    And that is really good in developing basic concepts ❤️
    But it will be more helpful I f u plzz upload some CP stuffs..😀
    Ps: Its just a request ...
    Bcz I watched many youtube videos but it's only your channel where I am getting proper explaination so that's why I request you to start a CP and DS Algo series too..❤️❤️

  • @aayushibhavsar7864
    @aayushibhavsar7864 2 роки тому +1

    Sir please make video on smart pointer and its types

  • @dalvinder_kaur
    @dalvinder_kaur 2 роки тому

    Thankyou so much 🙏

  • @jairambhardwaj716
    @jairambhardwaj716 4 роки тому

    Thanku bro ❤😊

  • @abhinavkulkarni4274
    @abhinavkulkarni4274 4 роки тому +1

    Please Upload next tutorial of Django blog on English channel as early as possible

  • @cosmic_021
    @cosmic_021 4 роки тому

    Always support you sir

  • @bestedmmusic512
    @bestedmmusic512 4 роки тому +1

    Upload next video Harry bhai
    I waiting 😍😁

  • @ashishsalve9139
    @ashishsalve9139 4 роки тому

    Harry bhai Data structures ke liye books suggest karo

  • @mohdkashanchaudhary2387
    @mohdkashanchaudhary2387 4 роки тому +1

    Sir will u please create a playlist on ds and algorithms please sir

  • @dotcodinggamerz319
    @dotcodinggamerz319 2 роки тому +3

    Codewallah

  • @YashDabhade-cr5my
    @YashDabhade-cr5my 4 роки тому +1

    Hello Harry Bhai,Will you please make some fun projects in C++

  • @RoyBoyLab
    @RoyBoyLab 3 роки тому

    Samajha gya 😌

  • @AmitKumar-li4uy
    @AmitKumar-li4uy 4 роки тому +1

    Bhaiya files me opening reading and writing bhi pdhana

  • @sudhanshujaiswal9699
    @sudhanshujaiswal9699 2 роки тому +3

    Watched 3 times this video still "this" is out of range

    • @rudraraval6274
      @rudraraval6274 2 роки тому +1

      yes bro same situation
      just understood first use
      ke jab variable ka nam same ho vo vala case

  • @Elon-musk-007
    @Elon-musk-007 4 роки тому +2

    Why is the operator overloading topic not covered??? isn't it important?

  • @bhupeshdeka3820
    @bhupeshdeka3820 4 роки тому

    First of all thanks for this amazing classes.. and i have a question haw many videos in this playlists yet to come..????????? Plz reply.

  • @suvajitpaul2193
    @suvajitpaul2193 4 роки тому +1

    Nice

  • @nitinmandve3737
    @nitinmandve3737 4 роки тому +1

    Harry bhai i waiting for data structure

  • @samkhan2132
    @samkhan2132 4 роки тому +1

    Sir ji ml ka next part kab aaega? plz sir reply kar do 🙇

  • @spandanjoshi3569
    @spandanjoshi3569 4 роки тому

    Bhai seo pe ek dedicated video banao .

  • @ravikaramunge8028
    @ravikaramunge8028 4 роки тому +1

    Please make Lectures on Java

  • @satwiksharma3186
    @satwiksharma3186 3 роки тому +2

    why is the & operator used after A in the setdata function declaration ? Plzzz helppp anyone!!!

    • @David-mk8kh
      @David-mk8kh 2 роки тому

      same doubt bro. Do you find the answer bro? Help me