function
In programming, a self-contained software routine that performs a task. Functions can do a large amount of processing or as little as adding two numbers and deriving a result. Values are passed to the function, and values may be returned. Or, the function may just perform the operation and not return a resulting value. The concept of a function within a program is that, once written, it can be used over and over again without the programmer having to duplicate the same lines of code in the program each time that same processing is desired.
Standard and Programmer-Defined
Programming languages provide a set of standard functions as well as allow programmers to define their own functions. For example, the C and C++ programming languages are built entirely of functions and always contain a "main" function.
The Application Programming Interface (API)
Functions in one program can also be called for by other programs and shared. For example, operating systems can contain more than a thousand functions to display data, print, read and write disks and perform a myriad of tasks. Programmers write their applications to interact with the OS using these functions. This list of functions is called the "application programming interface" (API).
Function Calls
Functions are activated by placing a "function call" statement in the program. The function call often includes values (parameters) that are passed to the function. When called, the function performs the operation and returns control to the instruction following the call. The function may return a value or not. Writing a program in a language such as C/C++ involves calling language functions, one's own functions and operating system functions (APIs). There is a whole lot of function calling. See function prototype, API and interface.
A Function Call Example: Open and Read
The example below shows two very simplified API functions to open and read a file.
handle = open("budget.txt");
size = read(handle, InputBuffer, length);
Computer Desktop Encyclopedia THIS DEFINITION IS FOR PERSONAL USE ONLY
All other reproduction is strictly prohibited without permission from the publisher.
Copyright © 1981-2009 by Computer Language Company Inc. All rights reserved.
| Topic | Replies | Latest Post |
|---|---|---|
| Function of the word 'intent' | 13 | 2 months ago |
| Can adverbial clause function as nominal? | 9 | 5 months ago |
| The Function of 'open' | 8 | 5 months ago |
| Function of Participle | 3 | 6 months ago |
| Function of Infinitive Phrase | 6 | 8 months ago |
Share on Facebook