From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Using pointers to manipulate data - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Using pointers to manipulate data
- [Instructor] To become familiar with the concept of pointers it helps to run a few basic exercises. These aren't the real world way you'll use pointers, but they help illustrate the concept. So, in this exercise file, you see two integer variables created, alpha, and a pointer variable, ptr. Both are of the integer data type, as declared in lines 5 and 6. Line 8 initializes variable alpha, line 9 initializes pointer variable ptr to the address of alpha, the location where the program stores alpha in memory add runtime. Both addresses are output in the next two lines, the printf statements %p conversion character displays a memory location value. Build and run. Now, the values you see on your system will be different than those show here, but they're both identical. In this code, the value of variable alpha is displayed, both directly and through pointer ptr. Line 11 uses ptr in both its modes. First, as an address, and then to display the contents of that address. Build and run. And…
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
-
-
-
-
-
Understanding pointers3m 19s
-
Using pointers to manipulate data2m 28s
-
Doing pointer math2m 57s
-
Comparing arrays and pointers3m 55s
-
Allocating storage3m 15s
-
Working with a pointer array3m 38s
-
Using pointers in structures3m 30s
-
Passing pointers to functions2m 57s
-
Returning pointers2m 39s
-
Challenge: Create a pointer array54s
-
Solution: Create a pointer array2m 23s
-
-
-
-