Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Q: What is the difference between function declaration and function define with exp
#1
Subject: Functions of C
Dear sir,

1. Q: What is the difference between function declaration and function define with example?
Reply
#2
Dear Student,
A function declaration is like a variable declaration; its purpose is simply to provide the compiler with all the information it needs for that particular function which we want to use in our program. The compiler does not need to know how the function works (its body). It only needs to know the function’s name, the number and types of its parameters, and its return type. This is precisely the information contained in the function’s declaration. Suppose we have a function which takes two integer type values and then return their sum which is also in integer type so its function declaration is given below:

int sum(int, int);

looking at the above function declaration, we can know that this function named "sum" takes two arguments of integer type and return an integer type value. Function declaration is also called function prototype.

On the other hand, Function definitions differ from function declarations in that they supply function bodies — the code that makes up the function. Function definition for above mentioned is given below:

int sum(int a, int b)
{
int c = a + b;
return c;
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why we use inline function if there are simple function available, or what is the spa Vuhelper 0 21,987 05-31-2012, 01:51 AM
Last Post: Vuhelper
  Default Function Argument with example Vuhelper 0 13,339 05-31-2012, 01:47 AM
Last Post: Vuhelper
  What is the difference among calloc function ,malloc function and recalloc function? Vuhelper 0 34,597 05-31-2012, 01:46 AM
Last Post: Vuhelper
  What is Function Overloading in C++ Vuhelper 0 5,406 05-31-2012, 01:45 AM
Last Post: Vuhelper
  offline function in C++ Vuhelper 0 3,634 05-31-2012, 01:42 AM
Last Post: Vuhelper
  i take input from getchar(); function in program in C++ 2012 Vuhelper 0 3,001 05-31-2012, 01:40 AM
Last Post: Vuhelper
  how we used the 1-calloc Function 2- malloc Function 3- free () 4- realloc Function i Vuhelper 1 31,145 05-31-2012, 01:35 AM
Last Post: Vuhelper
  What are the function of IO ports in C++ Vuhelper 0 3,605 05-31-2012, 01:27 AM
Last Post: Vuhelper
  What is difference among Binary Tree, Complete Binary Tree and Binary Search Tree? Vuhelper 2 4,345 03-18-2012, 12:47 AM
Last Post: Xpert
  Explain the difference b/w Null Pointer and Null Nodes? C++ 2012 Vuhelper 0 1,953 01-06-2012, 12:24 AM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)