From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,600 courses taught by industry experts.
Solution: Passing values - C Tutorial
From the course: Complete Guide to C Programming Foundations
Solution: Passing values
(upbeat music) - [Narrator] For my solution, the line function requires two arguments, as seen by the function call here, all coded appropriately. The function returns no value, so it's void. It needs an integer value, which I've named length and a character value, C. The function needs a loop to repeat length times. Now, I could create another variable to use as the loop's condition, but instead, I'll just write the for loop like this. No initiation is needed as the value of length is already set, as long as it's greater than zero, decrement length for each iteration of the loop, the sole looping statement outputs the character past, C. Then I'll add a new line output to wrap it up. Make sure you have that closing brace in there. The line function is written first, so I don't need to prototype it. Run to test. There's the line. The beauty of functions like this is that you can specify a line of any length or character. Just set the proper arguments here and the function does the…
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
-
-
-
-
-
-
-