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

Returning a value from a function - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

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…

Contents