Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the difference between declare function and define function ?

user-image
Question added by Deleted user
Date Posted: 2015/08/09
Geetha Asokan
by Geetha Asokan , Lecturer , St. Patrick's College

Declaring a Function Means -> Giving a name to the function with return type and parameters. 

Example : int add(int a, int b)

Defining a Function Means -> Giving a method body to a declared function or we can say calling a declared function.

Example: int add(int a1, int b1)

                  {

                       int c = a1+b1;

                        return(c);

                   }

Emad Mohammed said abdalla
by Emad Mohammed said abdalla , ERP & IT Software, operation general manager . , AL DOHA Company

When you declare a variable, a function, or even a class all you are doing is saying: there is something with this name, and it has this type. The compiler can then handle most (but not all) uses of that name without needing the full definition of that name. Declaring a value--without defining it--allows you to write code that the compiler can understand without having to put all of the details. This is particularly useful if you are working with multiple source files, and you need to use a function in multiple files. You don't want to put the body of the function in multiple files, but you do need to provide a declaration for it.

So what does a declaration look like? For example, if you write:

int func();

 

This is a function declaration; it does not provide the body of the function, but it does tell the compiler that it can use this function and expect that it will be defined somewhere.

Deleted user
by Deleted user

Declaration : "Hey compiler when you see a function with this signature, treat it as legal"

Definition : "Do this when you are called from anywhere"

Mohamad Saeid Sayed Sulaiman
by Mohamad Saeid Sayed Sulaiman , Senior Software Engineer , Saudi Telecom Company - Stc

with define we write code of function that mean generate function not known before,

with declare no need to write code, my be exist in library and declare is first step before use it.

ajay gupta
by ajay gupta , Project , SOTL

Declaration Means  declare the method with return type , return type anything like void,int,string, list , object , array .. many more.. Best example for declaration is Interface in OOPs concept.

Interface Calc()

{

 int Sum(int num1,Num2);

 int Sub(int num1,Num2);

}

 

Definition of method is

 

Implement above interface in any class 

 Class Math : Calc

{

 public int Sum(int num1, int num2)

{

return num1+num2;

}

 public int Subm(int num1, int num2)

{

return num1-num2;

}

 

}

 

Also you can say declaration means Concrete or Abstract method.

 

Fatma Eid
by Fatma Eid , Software Embedded systems Engineer , The Egyptian Bureau for Engineering

Declaration of any thing (variable or function) means give it name and type

EX: int count;  count is variable with integer type

Definition some thing give it value

ex: count =10; for variable

 

 

More Questions Like This