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: Displaying an array - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
Solution: Displaying an array
(upbeat music) - [Instructor] Here is my solution. Because the base address of the string isn't changing in my solution, I declared the string by using a pointer shown here in line six. The string's length is calculated and stored in line nine and that value is used in the loop in line 10. The putchar statement at line 12 fetches the address of the string, plus the offset as represented by variable x. As the for loop spins the offset increases, accessing each character in the array. Both variables, text and x, must be enclosed in parenthesis. That way the calculation is made on the address and not the value at the address. That's basically a pointer expression that's the equivalent of array notation.
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)
-