Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
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);
}
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.
Declaration : "Hey compiler when you see a function with this signature, treat it as legal"
Definition : "Do this when you are called from anywhere"
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.
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.
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