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

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.

Contents