From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Passing arguments to a function - C Tutorial
From the course: Complete Guide to C Programming Foundations
Passing arguments to a function
- [Instructor] Arguments passed to a function must be given a data type, which is set in the functions argument list. In this source code file, the repeat function expects an integer argument which it names count. Count is used within the function as a variable. You need not redeclare it inside the function. The value of the variable passed is set in the function call, here in the main function, first at line 15 with literal value 1, and again at line 17 with literal value 3. The function sends a chunk of text to output, repeating it as many times as indicated by the argument. The repeat function doesn't return a value, so it's typed as a void function. Run to see the results. And I know these guys. In this exercise file, the function average consumes three floating point values assigned to variables a, b, and c within the function. The average is computed and saved in variable avg, which is return. The average function is a float function returning a float value. This function is…
Contents
-
-
-
-
-
-
-
Understanding functions3m 11s
-
(Locked)
Creating a function4m 52s
-
(Locked)
Challenge: Writing a function39s
-
(Locked)
Solution: Writing a function1m 49s
-
(Locked)
Returning a value from a function2m 23s
-
(Locked)
Challenge: Returning a value53s
-
(Locked)
Solution: Returning a value2m
-
(Locked)
Passing arguments to a function2m 22s
-
(Locked)
Challenge: Passing values41s
-
(Locked)
Solution: Passing values1m 50s
-
(Locked)
Using the main() function's arguments2m 13s
-
(Locked)
Retaining values in a function2m 34s
-
(Locked)
Creating recursive functions3m 44s
-
(Locked)
Chapter challenge: Write the functions1m 14s
-
(Locked)
Chapter solution: Write the functions2m 15s
-
-
-
-
-
-
-