Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere


Function In C++

A function is a group of statements.In function,statements are grouped together to perform a perticular task.
Some common functions provided by C++ are main(),strcat() to concatenate two strings, memcpy() to copy one memory location to another location,strcpy() whto copye one string into another string etc.
Every C++ program has at least one function, which is main(),you can write/use other function on the basis of your program functionality.
Each function performs a specific task.Functions are generally used for code seperation and code reuse.
If you have piece of code which do a perticular task and it is needed in other parts of programs also,then it is better to create a function,move that code insite function and used this function wherever it is required.
A function has two parts.
1-Function Declaration-A function declaration tells the compiler about a function's name, return type, and parameters.
2-Function Body-Body specifies that what that function will actually do , if someone uses it. It contains statement which perform the perticular task when someone will use this function.


Syntex-
Functions In C++ without Parameter

Functions In C++ with Parameter

Functions In C++ with Multiple Parameter


Example-
1-Function declaration without parameter:
Functions In C++ without Parameter


2-Function declaration with parameter:
Functions In C++ with Parameter

Function Name: Follow below coding standards while giving function name.
1-Function Name must not start with digits(1,2...),undescore(_) or dash(-).
2-Function Name should describe the functionality provided by function. e.g. Copy() function should be used to copy the content,function with name Delete() should be used to delete items etc.
3-Function Name name should not be too big.
4-Don't use reserve key word for your function name e.g. strcpy() is a function provided by C++, hence don't use this name for your function.