Introduction to C++ • Built-in functions – Functions which are available in C++ language standard library. • User-defined functions – Functions created by users. . Need for Functions To reduce size and complexity of the program we use Functions.
The programmers can make use of sub programs either writing their own functions or calling them from standard library. . Divide and Conquer • Complicated programs can be divided into manageable sub programs called functions. • A programmer can focus on developing, debugging and testing individual functions.
• Many programmers can work on different functions simultaneously. . Reusability • Few lines of code may be repeatedly used in different contexts. Duplication of the same code can be eliminated by using functions which improves the maintenance and reduce program size.
• Some functions can be called multiple times with different inputs. Chapter Page - - . Types of Functions Functions can be classified into two types, . Pre-defined or Built-in or Library Functions .
User-defined Function. C++ provides a rich collection of functions ready to be used for various tasks. The tasks to be performed by each of these are already written, debugged and compiled, their definitions alone are grouped and stored in files called header files . Such ready-to-use sub programs are called pre- defined functions or built-in functions.
C++ also provides the facility to create new functions for specific task as per user requirement. The name of the task and data required (arguments) are decided by the user and hence they are known as User- defined functions. . C++ Header Files and Built-in Functions Header files provide function prototype and definitions for library functions.
Data types and constants used with the library functions are also defined in them. A header file can be identified by their file extension .h. A single header file may contain multiple built-in functions. For example: stdio.h is a header file that contains pre-defined “standard input/ output” functions.
. . Standard input/output (stdio.h) This header file defines the standard I/O predefined functions getchar(), putchar(), gets(), puts() and etc. .
. . getchar() and putchar() functions