0% found this document useful (0 votes)
12 views2 pages

Functions

A function is a set of instructions that are designed to perform a specific task independently. There are two kinds of functions: built-in functions and user-defined functions. Built-in functions are already defined as part of the programming language and can be used in any program, while user-defined functions are created by the user as part of a program to perform a specific task. User-defined functions have three parts: a function declaration, definition, and calling.

Uploaded by

Rizwan Iqbal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Functions

A function is a set of instructions that are designed to perform a specific task independently. There are two kinds of functions: built-in functions and user-defined functions. Built-in functions are already defined as part of the programming language and can be used in any program, while user-defined functions are created by the user as part of a program to perform a specific task. User-defined functions have three parts: a function declaration, definition, and calling.

Uploaded by

Rizwan Iqbal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

FUNCTIONS

A function is a set of instructions that are designed to perform a specific task. A function
is a complete and independent program. It is executed by the main function or any other
function of the program to perform its task.

There are two kinds of functions


1. Built in functions
2. User defined functions
Built in functions

Functions that have already been defined as a part of the language and can
be used in any program are called built in functions.
Example:
<string.h> header file contains functions that are used to process strings
strlen:
stands for string length
this function is used to find length of a string
it counts the total number of characters including spaces.null character is excluded
syntax:
int strlen(string);
code using it:
#include<iostream.h>
#include<string.h>
main()
{
char str[10];
cout<<”enter any string”;
cin>>str;
cout<<”length of string is =”;
cout<<strlen(str);
}

output:
suppose user enters itc then output will be:
3

User defined functions


Functions created by user are called user defined functions.
These functions are written as part of a program to perform a specific task.
These functions are written for specific use.
It has 3 parts
1. Function declaration
2. Function definition
3. Function calling
Example:
#include<iostream.h>
int main()
{
int sum (int, int);

sum(3,4);
}
int sum(int a, int b)
{
int c=a+b;
cout<<”sum =”<<c;
}

output:
7

You might also like