From the course: Advanced C Programming: Optimize Performance and Efficiency
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Incrementing a pointer - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
Solution: Incrementing a pointer
(upbeat music) - [Instructor] For my solution, I used two variables, f and fptr. The pointer variable is initialized at line seven, the ampersand operator is used. At line eight, the value 89 is assigned by using the asterisk operator on the pointer. Same operator is used line nine to display the value. At line 10, the increment operator is used. It prefixes the asterisks operator, which allows for the value at the address to be incremented. And there's the result. Now, say that you wanted to put the increment operator after point or variable, as in *fptr++. In this case, what you're doing is incrementing something after it's been used. But what you're incrementing is the address, not the value at the address. You'll still see the same value displayed but the pointer is incremented to a point at rubbish in memory. Again, where you put the operators important here, thanks to the order of precedence, which is the topic…
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
-
-
-
-
-
-
-
(Locked)
When to use the ampersand operator4m 20s
-
(Locked)
How to bind the asterisk operator4m 51s
-
(Locked)
Challenge: Incrementing a pointer23s
-
(Locked)
Solution: Incrementing a pointer1m 10s
-
(Locked)
Understanding arrays and pointers4m 4s
-
(Locked)
Challenge: Displaying an array29s
-
(Locked)
Solution: Displaying an array54s
-
(Locked)
Obeying the order of precedence6m 27s
-
(Locked)
-