Function declarations and function definitions in cpp, C/C++ Programming

FUNCTIONS

It refers to a subprogram that is meant to do a certain task. It is basically used to execute a set of operations and return information to the main or calling function.

 

Basic Format:

return_data_type function_name(data_type par1, data_type par2,...)
{

Statement  1;

Statement  2;

}

Function Declarations and Function Definitions

Every function in program must have a function declaration and a function definition. Function declaration refers to the functions name, return data type and parameters (function prototype) while Function definition refers to the implementation of a particular function. Function declaration and function definition appear together to form a function

 

Static type checking

It refers to the checking of the data types used in all functions are appropriate to the actual function

requirements. This ensures that any function cannot be called with wrong number of parameters or

inappropriate argument types  i.e. C++ does not allow any function to be used before it has been declared and the reason is that the compiler can perform static type checking.

 

Function prototypes

This is a function declaration statement that informs the compiler of the type of data returned by the
functions, the number of parameters the function expects and order in which they are expected.
Format:

return_type function_name  (list of parameters); 

 

Posted Date: 8/21/2012 11:48:25 AM | Location : United States







Related Discussions:- Function declarations and function definitions in cpp, Assignment Help, Ask Question on Function declarations and function definitions in cpp, Get Answer, Expert's Help, Function declarations and function definitions in cpp Discussions

Write discussion on Function declarations and function definitions in cpp
Your posts are moderated
Related Questions
There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Define the Logical Operators in c language? The Logical operators deals with the ways the relationships are able to connected. C has the following three logical operators

The procedure +, * and list take arbitrary numbers of arguments. One way to define such a procedure is to use define with dotted-tail notation. In a procedure definition, a paramet

Question 1 Implement a class stack which simulates the operations of the stack allowing LIFO operations. Also implement push and pop operations for the stack 2 Explain the c

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

You are to write a C++ program which will compute the gross pay, Social Security Tax, Income Tax and net pay for an employee. The program needs to prompt for and read the employ

Explain the different types of errors in PHP. Warnings, Notices and Fatal errors are the types of errors in PHP Notices: Notices signifies non-critical errors, i.e. ac

Q: however shouldn't I always use a printOn() method instead of a friend function? A: No. The usual cause people wish to always use a printOn() method instead of  a friend fu

Define global variable in c++ program: How to define a global variable and need of global variable in c++ program. int main() {    int m=20;    clrscr();    for

smugglers transfer the messages from one to another by using the mobile