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
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#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 22,005 05-31-2012, 01:51 AM
Last Post: Vuhelper
  Default Function Argument with example Vuhelper 0 13,366 05-31-2012, 01:47 AM
Last Post: Vuhelper
  What is the difference among calloc function ,malloc function and recalloc function? Vuhelper 0 34,631 05-31-2012, 01:46 AM
Last Post: Vuhelper
  What is Function Overloading in C++ Vuhelper 0 5,436 05-31-2012, 01:45 AM
Last Post: Vuhelper
  offline function in C++ Vuhelper 0 3,659 05-31-2012, 01:42 AM
Last Post: Vuhelper
  i take input from getchar(); function in program in C++ 2012 Vuhelper 0 3,030 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,178 05-31-2012, 01:35 AM
Last Post: Vuhelper
  What are the function of IO ports in C++ Vuhelper 0 3,629 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,381 03-18-2012, 12:47 AM
Last Post: Xpert
  Explain the difference b/w Null Pointer and Null Nodes? C++ 2012 Vuhelper 0 1,971 01-06-2012, 12:24 AM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support