From the course: C Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Passing arguments to a function - C Tutorial
From the course: C Essential Training
Passing arguments to a function
- [Instructor] Arguments passed to a function must be given a data type, which is set in the function's argument list. In this exercise file, the repeat function expects an integer argument count. Count is used within the function to set a loop. You do not need to re-declare the variable passed within the function. The value of the variable passed is set in the function call here in the main function at lines 15, and again, at line 17. The function sends a chunk of text to output, repeating it as many times as was specified in the argument. The repeat function doesn't return a value, so it's typed as a void function, build and run to see the results. And this is true line. I know these two guys. In this exercise file, the function average consumes three floating point values as its arguments. These values are assigned, within the function, to variables a, b, and c. The average is then computed, and the result…
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
-
-
-
-
-
-
-
Understanding functions3m 21s
-
(Locked)
Creating a function3m 28s
-
(Locked)
Challenge: Writing a function46s
-
(Locked)
Solution: Writing a function1m 10s
-
(Locked)
Returning a value from a function2m 33s
-
(Locked)
Challenge: Returning a value42s
-
(Locked)
Solution: Returning a value1m 40s
-
(Locked)
Passing arguments to a function1m 52s
-
(Locked)
Challenge: Passing values44s
-
(Locked)
Solution: Passing values1m 22s
-
(Locked)
Using the main() function's arguments3m 30s
-
(Locked)
Retaining values in a function2m 58s
-
(Locked)
Creating recursive functions3m 53s
-
(Locked)
Challenge: Complete the code1m 14s
-
(Locked)
Solution: Complete the code1m 31s
-
-