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.
Solution: Passing values - C Tutorial
From the course: C Essential Training
Solution: Passing values
(upbeat music) - [Instructor] For my solution, here is my line function. The function has two arguments, integer length and character c. Within the function, integer variable a is used as a looping variable specifically at line seven. It loops from zero to the value, length which is the number passed. And the loop's statement is putchar, which outputs the character passed. I added a putchar function here at line nine, in order to ensure that the output appears on a line by itself. Build and Run, and there's the line. The beauty of functions like this is that you can specify a line of any length or any character. Just set the proper arguments and the function does the work. So down here in the main function, you could add another line function. Say, line with 20 and do dollar signs. Save this change, Build and Run, and you can see the flexibility of the line function and the value of having such arguments.…
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
-
-