Functions declared of a certain data type must return that data type, accomplished by using the return keyword, which specifies the value to return. Not all functions need to return a value, such as a void function, though any function can use the return keyword to exit early.
- [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 here in the return statement are optional. …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.