Functions
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.
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
sum(3,4);
}
int sum(int a, int b)
{
int c=a+b;
cout<<”sum =”<<c;
}
output:
7