Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

Creating Functions That Return a Value

The final addition to making your functions as practical as the standard C library functions is to have them return values. This is accomplished using the return statement, which you've already been using in the main function. You can return any single value from your function:

return 1;

The returned value can even be based on a variable's value:

int num = 8;
return num;

Any function that returns a value must have a proper prototype and definition, both of which must indicate the type of value returned. You've already seen this with the main function (which returns an int). Here's another sample function definition:

int my_func (void) {
   return 27;
}

You can assign the returned values to variables when ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book