From the course: Advanced C Programming: Optimize Performance and Efficiency

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Setting up a static variable

Solution: Setting up a static variable

(upbeat music) - [Instructor] The key part of the solution is to declare the array of primes as a static int array, which is done here at line 5. That's pretty much it. The array is returned at line 7. Note that the function is declared as an integer pointer. An array isn't returned from the function but its address is. That address is fetched in the main function at line 15. You'll see that the array variable is also an integer pointer declared at line 13. A for loop at lines 16 and 17 displays the values. Remember that your solution can look different. That's okay. But you must declare the array as a static int, otherwise the values displayed will be unpredictable.

Contents