From the course: Master C Language Pointers

Unlock the full course today

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

Accessing the buffer

Accessing the buffer - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

Accessing the buffer

- To access allocated memory, you use a pointer. Two approaches can be used. A single pointer can walk through the data. Or two pointers can manage a base and an offset. In both cases, pointer math is used to reference the various data chunks in the buffer. Pointer math means manipulating a pointer to modify its address according to the size of data the pointer references. For example, incrementing integer pointer p doesn't add one to the address. Instead, it adds one integer-sized memory chunk. After incrementing pointer p, it references the next integer value in memory. Likewise, when c points to a character buffer, c+1 references the second character in the buffer. When d references a buffer of double values, d+4 references the fifth double value in the buffer. In this code, integer pointer p is allocated to a chunk of memory. The for loop of line 17 assigns values. The values assigned to the address of pointer p at…

Contents