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 - C Tutorial
From the course: Master C Language Pointers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Comparing arrays and pointers3m 36s
-
(Locked)
Allocating storage3m 29s
-
(Locked)
Exploring allocation functions4m 58s
-
(Locked)
Accessing the buffer3m 41s
-
(Locked)
Working with pointers in structures2m 18s
-
(Locked)
Creating structure pointers3m 29s
-
(Locked)
Saving pointers and buffers4m 31s
-
(Locked)
Challenge: Saving and reading a record1m 6s
-
(Locked)
Solution: Saving and reading a record2m 15s
-
-
-