From the course: Secure Coding in C

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Performing pointer math

Performing pointer math - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Performing pointer math

- [Narrator] Pointer variables reference buffers of a specific data type. This requirement is necessary because different data types occupy different sized chunks of memory. In this code storage for 10 integer values is allocated at line 10. Pointer a references integer sized chunks in memory. This is how the buffer is filled with integers. Pointer a, at line 21, increments for each iteration of the for loop. As it does, it points to the next successive integer sized memory address within the buffer. Yet, there's a problem because pointer a no longer references the base address of allocated memory. Some pointer math is required to reset that location back to the start of the buffer. In this exercise file, the pointer math is performed at line 25. The address in variable a is reduced by 10. 10 what? 10 integer sized chunks of memory. The effect is that once again, variable a points at the buffer's base, so the…

Contents