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 - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
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.
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)
Set up an external variable4m 16s
-
(Locked)
Typecast variables4m 46s
-
(Locked)
Challenge: Specifying a cast26s
-
(Locked)
Solution: Specifying a cast51s
-
(Locked)
Take advantage of static variables3m 20s
-
(Locked)
Challenge: Setting up a static variable23s
-
(Locked)
Solution: Setting up a static variable54s
-
(Locked)
-
-
-