Arduino Pointers and Memory Addresses

🤩 How much Arduino can you learn in 7 Days? 👇
bit.ly/7_Day_Arduino_Challenge
**Learn to program and prototype with Arduino now! Join our membership.**
bit.ly/3hvsDqf
**We designed this circuit board for beginners!**
Kit-On-A-Shield: amzn.to/3lfWClU
FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook: / programmingelectronics...
Twitter: / progelecacademy
Website: www.programmingelectronics.com/
________________________________
Hello, I hope you're doing fantastic. All right, so you might be wondering what are these memory addresses? What are they actually doing? What purpose do they serve? Well, let me tell you, these addresses are key for how the processor will know where to look for data when it's running your program, they literally direct the processor where to put data in memory, and where to find the data from memory. So let's think about a physical address for a moment. Say I live at 42 Honolulu Blvd., that's like my address. if you wanna find me. You open your phones mapping application and say take me to 42 Honolulu Boulevard. Then you hop in your private Learjet and fly over, you grab an Uber to 42 Honolulu Boulevard and what are you gonna find there? Well, you're gonna find me, that's my address. Now, I may be out practicing my nunchuck skills or whatever, but nonetheless my address will point to where I am. So what do these memory addresses have to do with pointers? Well, kind of everything. So let's go back to our pointer definition. A pointer is a variable that holds the memory address of another variable. So a pointer holds the address of another variable. If I had an integer pointer named pScore, which pointed to the score variable, then pScore would be holding the value 104. Likewise, if I have a float pointer named pResult, which pointed to result, then pResult would be holding the value 106, so these pointers hold addresses If I had an integer pointer bucket, I would put integer addresses in that bucket. If I had a float pointer bucket, I could put float addresses in that bucket. So how do we get these variable addresses, and how do we get a pointer to point at the address? So let's start with the first question. It turns out, to get a variables address is really simple, you just use the & operator in front of a variable name. This is also called the reference operator. It's literally that easy, you just put the little & sign in front of a variable name, and now it's gonna give you the address of that variable in memory. Now listen, you probably don't believe me, hey, fair enough, I don't really believe me either, so why don't we put this to a test? What if we make some variables and then print their addresses to the serial monitor window using the ampersand operator in front of the variable name? So here we are in the Arduino IDE, what I'm gonna do is create some variables, then I'm gonna print the memory addresses of those variables using the ampersand operator, and this is gonna prove that I'm not lying to you. So let's do this. All right, so I've created four variables, a byte, a character, an integer, and a float. We've set them equal to different values. So I did this first part, created some variables. Now what I'm gonna do is print the memory addresses of these variables, using the ampersand operator. So let me do that. So here I'm printing &ledPin, so this is at ampersand operator, and this is saying, give me the address of ledPin. Now here's the deal, and this might sound a little weird but just wanna try to explain this as best I can. Serial print is not designed to be able to display an address, a variable address, so we have to cast the address as something else, something that Serial print can print, like an integer or a long, and a common way to do this is to cast it as an unsigned long. So I'm gonna do that right now just to show you. So what this section of code right here is doing is it's taking the address of ledPin, and it's casting it as an unsigned long, and that's simply so that we can print the address out on the serial monitor window. All right, so I'm gonna do the same thing for these other variables and then we'll see the results on the serial monitor window to determine whether or not I am a cold, hard liar. All right, so let's take a look at the output here. Our byte ledPin is being stored at memory address 2299, and we said that a byte takes up one byte of memory, so where would the next variable get stored after 2299? Be it 2298?
**About Us:**
This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board.
**We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.**

Пікірлер: 23

  • @stevenbartlett7925
    @stevenbartlett7925 Жыл бұрын

    Another great video!!! I am impressed with each and every video. Your videos are one of the best resources for the Arduino community. Keep up the good work.

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Thanks so much Steven! Really appreciate that!

  • @sukeen8038
    @sukeen8038 Жыл бұрын

    Teacher, you came out with this amazing course on time to stop me from driving crazy into this concept:) Thanks!

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Thanks so much for watching Su Keen!

  • @ianbertenshaw4350
    @ianbertenshaw4350 Жыл бұрын

    This is really relevant when you need to economize on your memory .

  • @nara49veera12
    @nara49veera12 Жыл бұрын

    Always simple and effective. Love your command on the subject.

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Thanks so much!

  • @venug2617
    @venug26174 ай бұрын

    Beautifully done.......

  • @programmingelectronics

    @programmingelectronics

    4 ай бұрын

    Thank you!

  • @joshuapitong899
    @joshuapitong899 Жыл бұрын

    Really helpful.🙌

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Great!

  • @mickgibson370
    @mickgibson370 Жыл бұрын

    I watched the video completely! Google is lying! They hold mark down 3/4 of the video as watched!

  • @timkern9563
    @timkern9563 Жыл бұрын

    I don't see a "Buy Now" button anywhere.

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    If you go to our website pricing page we have a couple options: www.programmingelectronics.com/pricing Hope that helps Tim!

  • @krishnawa_
    @krishnawa_ Жыл бұрын

    Is this course avilable now?

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    It is going to be released soon. Probably in a week or so.

  • @ssekelopromise4886
    @ssekelopromise4886 Жыл бұрын

    Hi, PEA, I wrote you an email asking about something on your website, it has been some time. Is there any proper way to communicate with you other than the email I got from your site, if there's please can you please provide me with, I wanted to enroll in your courses.

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Hi S’sekelo - my apologies for the slow reply, we have been barraged by email so keeping up can be tough some times. I think you had asked about if you could use an Arduino simulator with training program. Tinkercad is a popular Arduino simulator, that works well and can probably get you pretty far in the training, however, you start to hit limits when we get into using different libraries and hardware.

  • @ssekelopromise4886

    @ssekelopromise4886

    Жыл бұрын

    @@programmingelectronics thanks for the reply, but I will enroll. And I will buy real arduino later, but thank you.

  • @keesdenheijer7283
    @keesdenheijer7283 Жыл бұрын

    42

  • @ricj9594
    @ricj9594 Жыл бұрын

    E

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    C