C pointers explained👉

Sdílet
Vložit
  • čas přidán 3. 06. 2024
  • C pointers tutorial example explained
    #C #pointers #tutorial
    void printAge(int *pAge)
    {
    printf("You are %d years old
    ", *pAge); //dereference
    }
    int main()
    {
    // pointer = a "variable-like" reference that holds a memory address to another variable, array, etc.
    // some tasks are performed more easily with pointers
    // * = indirection operator (value at address)
    int age = 21;
    int *pAge = &age;
    printAge(pAge);
    //printf("address of age: %p
    ", &age);
    //printf("value of pAge: %p
    ", pAge);
    //printf("size of age: %d bytes
    ", sizeof(age));
    //printf("size of pAge: %d bytes
    ", sizeof(pAge));
    //printf("value of age: %d
    ", age);
    //printf("value at stored address: %d
    ", *pAge); //dereferencing
    return 0;
    }
  • Věda a technologie

Komentáře • 128

  • @mindlessmeat4055
    @mindlessmeat4055 Před rokem +32

    Anytime I need to know something about programming, your channel is the first one I look for.

  • @HiiImChris
    @HiiImChris Před rokem +108

    Just some advice.to truly understand this concept is a thorough way to apply it to your programs, I think it's best to take it slow. Don't feel bad, in my lecture I slowly and methodically took notes for hours on a 30 minute video to grasp the idea as a noob. It's ok to take your time, not all of us are coding gods. The only objective you should have is understanding it, and for each person that learns differently it's going to take varying time. As long as you come out with the knowledge, than your knowledge is just as effective as anybody elses.

    • @SK-ow4vw
      @SK-ow4vw Před rokem +4

      I think that the conceptual problem about pointers begins much earlier than you might imagine. For example, let's take 'int age = 21" You said the integer 'age' has a value 21 AND an address. I then could easily say "well it also has a name 'age'. So now my question would be 'where is the string 'age' stored, where is the 'address' stored and where is the value stored.' Then I would ask 'how do you get to the actual integer value from the string 'age'? Surely to humans the string 'age' IS A POINTER to the value 21. So there is even confusion BEFORE one starts speaking about 'normal' pointers. As far as I understand it the compiler completely removes any reference to the string 'age'. Does it therefore replace the string 'age' in assembly code with the address where we can find the value 21? If so, the address that appears in the machine code IS A POINTER also to the value 21. Unfortunately we now don't have a name for it. So this whole issue for some of us needs to be cleared out of the way first before we can even start to talk about pointers.
      So in a nutshell: we need to know precisely what happens to the string 'age' in machine code.

    • @sueyourself5413
      @sueyourself5413 Před rokem

      @@SK-ow4vw No, no we don't. It's a reference of text, not a string.

    • @onlyeyeno
      @onlyeyeno Před 10 měsíci +4

      @@sueyourself5413 I believe You actually strengthened "*Sk-ow4vw*"s argument, by seemingly missing his point... As I read his comment, the "issue" is not if the "variable-name" (age) is a string or some other "datatype". Rather according to Sk-ow4vw the "crux" of this is the fact that when describing (and thinking about" the "concept of a variable", it has both and address, a value (held at that address) AND a "variable-Name". And so when explaining Pointers in a way that totally neglects to even mention the "handling and destiny" of the "variable name" You risk to "loose/confuse" people who think that "one step further".
      At least that's how I read SK-ow4vw's comment.
      Best regards.

  • @katarinaclaes2975
    @katarinaclaes2975 Před 2 měsíci +1

    nice explanation, your tips on what's good practice makes it way easier to understand

  • @tybargky461
    @tybargky461 Před rokem +13

    As a CS major @ Virginia Tech, you have blessed me with a foundation that builds my confidence!

  • @abhishekmaurya8330
    @abhishekmaurya8330 Před 2 lety +3

    Awesome sir keep it up. You have nice way of explanation

  • @spooders8943
    @spooders8943 Před 2 lety +10

    this was the clearest way someone has ever explained pointers to me. thanks

  • @provokator-provocateur7603
    @provokator-provocateur7603 Před 2 lety +29

    Great video. Can you make video about void pointers, array pointers, struct pointers as well?

  • @preethi2802
    @preethi2802 Před 3 měsíci

    Finally got a clear insight into what all these denotations in pointers mean. Thanks a ton, bro

  • @ajitghising8112
    @ajitghising8112 Před 4 měsíci

    You cleared my mind about pointer with one view. Thanks a lot. I will be coming to check more videos from your channel. I’m learning c atm. Really appreciate man 🎉

  • @juliannafotheringham7101

    great explanation, very clear, thank you!

  • @jamesharland3727
    @jamesharland3727 Před 11 měsíci +1

    This is really clear, thank you! Got me though a mental block I was having on Codecademy

  • @barsceylan4559
    @barsceylan4559 Před rokem +3

    Dude wtf!! You are a savior !!

  • @accumulator4825
    @accumulator4825 Před rokem +3

    Could you do a Scala series? That'd be so cool

  • @brahimkazzi5281
    @brahimkazzi5281 Před měsícem

    Thank you bro
    best course

  • @seyhaseng1077
    @seyhaseng1077 Před 2 lety +2

    It would be awesome if u teach or solve the problems of languages

  • @stephensagarinojr.4170
    @stephensagarinojr.4170 Před 11 měsíci +4

    I would really be glad if you'd make a video about double pointers. Many videos are on youtube but it hard to understand it. and when I watch your videos, I can understand it easily.
    I am so thankful for all the tutotiral you made

    • @A1cJ121
      @A1cJ121 Před 5 měsíci

      A double pointer is essentially a pointer that holds the value of the memory address of another pointer.
      int x= 5;
      int *pX = &x;
      int **pPX = &pX;

  • @SleepyAizawa69
    @SleepyAizawa69 Před 2 měsíci

    Hey bro thank you for your smooth well explained videos!❤

  • @NNNedlog
    @NNNedlog Před 2 lety +4

    your vids are always easy to follow along. Thanks a lot

  • @tylersantiago3810
    @tylersantiago3810 Před 7 měsíci

    bro, idk who you are, I don't know where you've been, idk what you do, but thank you, I love you 3000. I just watched this video and understood everything about pointers. It took my professor 3 class sessions to do so and I still didn't get it.

  • @omarabbas6541
    @omarabbas6541 Před 11 měsíci +2

    bro , you deserve more than like , comment and subscribe. You are amazing mashaAllah

  • @vesnapezer683
    @vesnapezer683 Před měsícem +1

    I love you seriously

  • @altprsn6929
    @altprsn6929 Před 9 měsíci

    Thank you!

  • @nocpich
    @nocpich Před 4 měsíci

    thanks! it helped me a lot

  • @naveenkumar1853
    @naveenkumar1853 Před 6 měsíci

    Excellent😊😊😊

  • @ahiamatagabriel5696
    @ahiamatagabriel5696 Před 2 lety +1

    Thank You.

  • @joevaghn457
    @joevaghn457 Před 2 měsíci +1

    I've never really grasped why pointers are somehow really hard to understand for some people. I'm not trying to be condescending. I'm really not! It's literally a memory address. There's nothing more to think about other than type casting pointers and pointer arithmetic, imho. When using pointers, all your doing is working with the address of something that exists somewhere else in memory. Good video tho, it was really useful. I honestly find useful

    • @SteveCatalunyaSE
      @SteveCatalunyaSE Před měsícem

      As a beginner my issues with understanding have been:
      - Why the need to define the type of the underlying value if we are always talking about its address?
      - Why confusingly re-use the asterisk for different, but associated purposes.

    • @joevaghn457
      @joevaghn457 Před měsícem

      @@SteveCatalunyaSE ah,
      So the type-of-pointer thing is so that the compiler knows how many bytes to advance the pointer ( pointer arithmetic: ++, +=, etc ).
      The reuse-of-asterisk is just for declaration. All I care about is if the asterisk is on value, it’s a dereference, if it’s on a declaration, then it’s a pointer.
      I hate dealing with multidimensional pointers beyond 3 levels. That stuff is extreme lol

  • @eeneemeenee6236
    @eeneemeenee6236 Před rokem +1

    You're awesome bruh

  • @justiceessiel6123
    @justiceessiel6123 Před 5 měsíci

    I have understood golang pointers by understand C pointers

  • @hakant.5806
    @hakant.5806 Před 5 měsíci

    Pretty useful

  • @ucheogordiunor4020
    @ucheogordiunor4020 Před 5 měsíci

    Great video,can you make video on creating a simple shell in C

  • @redmor
    @redmor Před rokem +1

    thanks bro

  • @lookwithme3083
    @lookwithme3083 Před 2 lety +1

    I have a question how can somebody make so amazing hell videos.

  • @Nathan00at78Uuiu
    @Nathan00at78Uuiu Před 5 měsíci

    love being a fellow bro.

  • @user-tp8gj6fu3n
    @user-tp8gj6fu3n Před 7 měsíci

    love this

  • @tushar8983
    @tushar8983 Před rokem +1

    way too underrated

  • @issker8840
    @issker8840 Před rokem +1

    thx!

  • @frzy970
    @frzy970 Před 7 měsíci

    thanks😄

  • @krateskim4169
    @krateskim4169 Před 9 měsíci

    nice video

  • @sanjaykannan4549
    @sanjaykannan4549 Před rokem +2

    top G

  • @danielndobe1257
    @danielndobe1257 Před 10 měsíci

    awesome

  • @michiDerMatt
    @michiDerMatt Před 18 dny

    The size of the pointer depends on if its running on 32 or 64 bit architecture right?

  • @izawasinsie55
    @izawasinsie55 Před 3 měsíci

    U saved me in exams

  • @aymanbou4847
    @aymanbou4847 Před 5 měsíci

    The best

  • @ironmonkey1990
    @ironmonkey1990 Před 2 měsíci

    very nice

  • @hoyorkilleader6021
    @hoyorkilleader6021 Před rokem +1

    Mitico!

  • @boyar3033
    @boyar3033 Před 5 měsíci

    Thanks Biggus Chaddus

  • @14Elijah
    @14Elijah Před měsícem +1

    I prayed 😇🙏

  • @danegaming9080
    @danegaming9080 Před 7 měsíci

    nice

  • @PSIwolf39
    @PSIwolf39 Před 5 měsíci +1

    Here's some code I wrote using pointers:
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    void addition(int firstNumber, int secondNumber, int *pResult){
    *pResult = firstNumber + secondNumber;
    }
    int main(){
    int firstNumber = 20;
    int secondNumber = 39;
    int result;
    int* pResult = &result;
    addition(firstNumber,secondNumber,pResult);
    printf("%d+%d=%d",firstNumber,secondNumber,result);
    }

  • @Jordan-qi2dn
    @Jordan-qi2dn Před 2 dny

    In the example where you compare the sizes of the int variable and the pointer variable, why is the pointer 8 bytes and the age variable 4 bytes?
    Is the pointer variable larger due to it being a hexadecimal?

  • @pratiknvlogs
    @pratiknvlogs Před rokem +3

    Which compiler and IDE is best to practice programming

  • @Frozenflames-si8ch
    @Frozenflames-si8ch Před 2 měsíci

    good

  • @shervin9561
    @shervin9561 Před 5 měsíci

    Thanks

  • @llamallama7
    @llamallama7 Před rokem +7

    In what situations should I use pointers?

    • @RJ-or8bw
      @RJ-or8bw Před 8 měsíci

      If you need to use a lot of memory that’s not standard size.
      If you have a struct that contains a lot of different data types, you would use a pointer to this huge chunk of data to get it all.

  • @orangejuice7247
    @orangejuice7247 Před rokem +1

    it entered uncharred territory im WHEEZING

  • @Atomos_tech
    @Atomos_tech Před rokem +2

    Thanks for the video, but there is something I am wondering about why the address is changing always when I restart the program !?

    • @heyaglitz
      @heyaglitz Před rokem +3

      It's because your program won't always get assigned the same range of memory by Windows, it's normal and it's intended to be like that.

    • @Atomos_tech
      @Atomos_tech Před rokem +1

      @@heyaglitz OK, thank you

  • @tybargky461
    @tybargky461 Před rokem +1

    I LOVE YOU

  • @Garrison86
    @Garrison86 Před 2 lety +2

    Leaving a random comment down below.

  • @gustavo-rios
    @gustavo-rios Před rokem +2

    This is a comment for the youtube algorithm

  • @bhoumik911
    @bhoumik911 Před 6 měsíci

    letsgo

  • @entropic7768
    @entropic7768 Před 4 měsíci

    2nd time its really clicking for me, probably going to have to relearn this like 20 times lmao

  • @ameenalrawbdeh767
    @ameenalrawbdeh767 Před 6 dny

    i love you

  • @giaminhpham2281
    @giaminhpham2281 Před 2 lety +1

    This video is great.

  • @Jordan-qi2dn
    @Jordan-qi2dn Před 2 dny

    This channel is good, but I think you need to structure your videos better.
    What I mean is that you should do a better job of separating the examples you do instead of editing previous examples for the next ones for the sake of better comprehension.
    More comments would also be helpful to understand what exactly you're trying to convey.
    Thanks for teaching me python and C though!

  • @SoloRush-hl8jv
    @SoloRush-hl8jv Před rokem +1

    hey ya bro

  • @fadiloumarou8280
    @fadiloumarou8280 Před 2 lety +5

    if we declare the pointer as
    int *pAge;
    then pAge = &age does the compiler consider *pAge as a null value?

    • @dotcomwhiz
      @dotcomwhiz Před 2 lety +3

      nope it will assign an arbitrary integer at that address

  • @jaajmer1924
    @jaajmer1924 Před 6 měsíci

    amen

  • @czsani1787
    @czsani1787 Před měsícem

  • @stutikalan8265
    @stutikalan8265 Před 6 měsíci

    I told my dad that I was taking a C programming course....
    He offered to give me some pointers

  • @OMNI_INFINITY
    @OMNI_INFINITY Před 9 měsíci +1

    Would have been good to include a proper function and call. That was reason watched. Sigh…

  • @DelilBalci
    @DelilBalci Před 5 měsíci

    Brooo... This channel is absolutely great!

  • @zer0k4ge
    @zer0k4ge Před 5 měsíci

    Makes sense but I bet it’s difficult to apply

  • @randerins
    @randerins Před 10 měsíci +2

    Looks like heavy depression.

  • @salih.karahan
    @salih.karahan Před 2 lety +195

    Elhamdülillah 🤲🏻🤲🏻 I found one video that isn't hindi english accent

    • @shavilagt1072
      @shavilagt1072 Před rokem +1

      hocam öğrendiniz mi c'yi?

    • @SHOURYAAAA
      @SHOURYAAAA Před rokem +3

      Lmao. The problem is with you.
      I wont blame Indian people just because hindi is their language and are better at programming than the people of your country.

    • @diversiontv777
      @diversiontv777 Před 10 měsíci +1

      I hate hindi

    • @OMNI_INFINITY
      @OMNI_INFINITY Před 9 měsíci +20

      Haha. Translation: Found a video that is trustworthy.

    • @burstfireno1617
      @burstfireno1617 Před 4 měsíci

      😅

  • @dumcatgaming
    @dumcatgaming Před 5 měsíci +1

    yea im still confused

  • @pintertenan8057
    @pintertenan8057 Před 8 měsíci

    From a bro

  • @psyferinc.3573
    @psyferinc.3573 Před 2 měsíci

    sanks here's a comment.

  • @knangurbanov2957
    @knangurbanov2957 Před rokem +1

    r u 21 years old?

  • @user-fh1mx6pz3r
    @user-fh1mx6pz3r Před 18 hodinami

    why didnt u explain memory management

  • @user-fh1mx6pz3r
    @user-fh1mx6pz3r Před 18 dny

    i still dont understand the use case..

  • @nickpantsios703
    @nickpantsios703 Před 3 měsíci

  • @sandersnolan6895
    @sandersnolan6895 Před 2 lety +1

    一直觉得挺难理解的,大一的C语言期末考还挂了,hh

  • @zari_723
    @zari_723 Před rokem +1

    comment...

  • @burstfireno1617
    @burstfireno1617 Před 4 měsíci

    printf("value of pAge: %p
    ", pAge); Ehh how can this be value of pAge when the output is an address? Don't get it..

  • @VintageSytr
    @VintageSytr Před rokem +1

    comment

  • @czsani1787
    @czsani1787 Před měsícem

    ❤❤❤❤❤❤❤❤❤❤💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕❤❤

  • @rafo21pe
    @rafo21pe Před 6 měsíci

    this video was quite difficult to understand

  • @gor3947
    @gor3947 Před 7 měsíci

    apres du txa es

  • @szmidutm8556
    @szmidutm8556 Před 7 měsíci

    Jesus it looks so confusing and pointless :D.

  • @BroCodez
    @BroCodez  Před 2 lety +43

    #include
    void printAge(int *pAge)
    {
    printf("You are %d years old
    ", *pAge); //dereference
    }
    int main()
    {
    // pointer = a "variable-like" reference that holds a memory address to another variable, array, etc.
    // some tasks are performed more easily with pointers
    // * = indirection operator (value at address)
    int age = 21;
    int *pAge = &age;
    printAge(pAge);

    //printf("address of age: %p
    ", &age);
    //printf("value of pAge: %p
    ", &pAge);
    //printf("size of age: %d bytes
    ", sizeof(age));
    //printf("size of pAge: %d bytes
    ", sizeof(pAge));
    //printf("value of age: %d
    ", age);
    //printf("value at stored address: %d
    ", *pAge); //dereferencing
    return 0;
    }

    • @giaminhpham2281
      @giaminhpham2281 Před 2 lety +2

      can you make another code that use cin, cout pleaseee

  • @lakshayphogat7831
    @lakshayphogat7831 Před 7 měsíci

    thanks bro