From the course: C Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Returning a value from a function - C Tutorial
From the course: C Essential Training
Returning a value from a function
- [Instructor] Functions return a value, thanks to the return keyword. The value specified must match the functions data type. In this Exercise File, the randchar function returns the value of variable R. Variable R is a character variable and the function is a character function. Now the variable itself isn't returned, variable R is local or private to the randchar function. But its value is sent back to the main function. Here in the main function the randchar function, returns its character immediately for use in the putchar function, which is part of a loop that turns seven times. The goal is to build a random word. Build and run the code, UNBBACU that's how I pronounce it. The randchar function generates a random value at line nine. This value ranges between zero and 25. This value is increased by the value of character variable, A which results in an uppercase letter of the alphabet, randomized. The parentheses…
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
-
Creating a function3m 28s
-
Challenge: Writing a function46s
-
Solution: Writing a function1m 10s
-
Returning a value from a function2m 33s
-
Challenge: Returning a value42s
-
Solution: Returning a value1m 40s
-
Passing arguments to a function1m 52s
-
Challenge: Passing values44s
-
Solution: Passing values1m 22s
-
Using the main() function's arguments3m 30s
-
Retaining values in a function2m 58s
-
Creating recursive functions3m 53s
-
Challenge: Complete the code1m 14s
-
Solution: Complete the code1m 31s
-
-