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
Destructor: The purpose of destructor is to free the memory when the compiler memory is reduced or not enough to execute certain program. Sometimes there may several objects op

write a javaprogram to solve padovan string using java? program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring;

E v o l u t i o n of Software: In the past stage of programming the software's were developed in Machine language Using binary numbers 1's and 0's.  Later it convert

Program1: Write a program to find the factorial of a given number. The input is user given. Final output is printed out on to the screen. Program2: Write a program to gene

give a program to accept and print 2_D Array

write a c program chat illustrates the creation of child process using fork system call. One process finds sum of even series and other process finds sum of odd series.

THEORY OF COMPUTER PROGRAMMING

Explain about the strategies of implementation of the statecharts, Database Management System?

The project is to design and write a C++11/FLTKgame program with a graphical user interface.The game is based on "pancake sorting," as described at http://en.wikipedia.org/wiki/P

a padovan string p(n) for a natural number n is defined as p(0)=''x'' p(1)=''y'' p(2)=''z'' p(n)=p(n-2)+p(n-3),n>2