35. Getting Started with C++: Pointers in Math

Опубликовано: 21 Февраль 2023
на канале: Ognema's Tech Lab
17
2

In this video, we explore how pointers can be used in mathematical operations. We start by declaring an array called "ognema" with 5 elements. We then declare three pointers, og0, og1, and og2, that point to the first, second, and third elements of the array, respectively. We use the address-of operator (&) to get the memory addresses of the array elements.

Next, we print the memory addresses of og0, og1, and og2 using the cout statement. We then introduce the concept of pointer arithmetic by adding 2 to the memory address of og0 using the += operator. This operation does not change the memory address itself, but rather changes the element that the pointer is pointing to.

Finally, we print the new memory address of og0 to the console. This shows how we can use pointer arithmetic to move the pointer to different elements of an array without changing its memory address. By doing this, we can manipulate the data in the array through the pointers.