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

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