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
How would I use variables of a C++ object within a Lua function, and then call the Lua function from C++ code?

Question 1: (a) Explain clearly the following concepts using suitable examples of your own:- (i) concrete class v/s abstract class (ii) constructor v/s over

Question 1 Explain Abstract data types with its characteristics Question 2 Let us say your Learning Centre decides to store all the three types of student data Register

Aim: To implement a program for following string operations: Length of String. String Concatenation. Substring (provide start index and length) Find character a

Normal 0 false false false EN-US X-NONE X-NONE

explain Storage management: free storage pool, garbage collection, compaction, boundary tag method; Hash tables and hashing functions

A skilled programmer is required to build a standalone module to extract, parse and store in database tables, word count data from web pages and RSS feeds. The module will take

how to write c++ for function f(x)= 2x^3 -x^2 +10

In this sub-task will you implement three functions for the final three function prototypes that will do exactly the same as the three functions that you have just written. This ti

convert BST into sorted doubly linked list