From the course: C Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Passing values to a function

Passing values to a function - C Tutorial

From the course: C Essential Training

Passing values to a function

- [Instructor] Parameters are passed to a function by declaring them inside the parentheses of the function definition and passing them in the parentheses of the function call. This is func.cpp from Chapter 06 of the Exercise Files. Let's pass an integer to this function. I'll start by declaring an integer inside these parentheses. Let's say int a. And we'll print out the value of a so we see what it is. And then I'll pass a value inside the parentheses of the function call from main. We'll go ahead and build and run this. And you see that this value here gets passed the function and printed by the format statement, where it says the value is 47. A function may also have a default value. I can come up here and I can say the default value is 73. And now when I call it without a value, it will print value is 73. And when I call it with the value, it'll print value is 47. This allows a function to be called with either zero…

Contents