View Feed
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12829 Members
Join this group to post and comment.
nishcom • Aug 10, 2008

Definition and declaration

Would anyone please tell me what is the difference between Declaration and Definition in "c"?
MaRo • Aug 11, 2008
they're about the look of the function in a program

Definition is writing the function and how it is working like
void foo()
Declaration is just writing the function header to implement in another function like:
int main()
foo(); // this is declaration
return 0;
And of course to write a declaration there should be a definition to implement.
banu • Aug 11, 2008
Both are based on functions and variables mostly.
For declaration

void main()
write() is a function call which is declared.

For definition:
void write()
printf("enter the name");
Here the operation/function of write() is defined.
definition must be given before declaration.
i guess iam right
Amit Saste
Amit Saste • Aug 11, 2008
Would anyone please tell me what is the difference between Declaration and Definition in "c"?
Just giving simple example:

Cnsider following as function declaration:
public void add_ten_nos(int a[]); //This is Declaration

public void add_ten_nos(int a[])
int sum;
for(i=0;i<10;i++) //or whatever the Definition

Hope u got it!!
umesh936 • Aug 12, 2008
Last one is correct(Amit)

void display(); // it is declaration
int main()
display(); // here it is called
// now here is defination of function
void display()
printf(" my name is XYZ");
///it so simple..
mohanapriya • Aug 13, 2008
hi i am pri.... actuall dis is my 1st post so i dnt no whether i m posting it to the right place or not.....
i am in desperate need of a topic artificial inteligence on which i want to present a paper.....i feel engineering is absolutely not interesting until u do something please guide me ...
Mrunalini • Aug 13, 2008
Hi.. One more additional point is that..

Function Definitions also known as proto-type, they are just an intimation given to the Compiler that I will be using the proto typed function in the future code execution.

The syntax for Prototype is:
(Argument Data Types);
Here semicolon is a must, and must be declared before the Function Definition.

Whereas when a function is called the code which is executed is Function Definition, with a syntax:

(arguments and their Datatypes)// No semicolon
Body of the code

Where as if we consider a variable.
when you declare:
int a;
you are telling the compiler that I am going to use a variable 'a' as an integer variable, please allocate space for it.

So here 'a' stores the address which is allocated by the compiler.
When you say
a = 5;

The value 5 is set to the location 'a' in the memory.

Hope this was helpful.. 😀
Prasad Ajinkya
Prasad Ajinkya • Aug 13, 2008
Ill keep the difference simple.

Declaration - you are announcing to the compiler, that such and such function exists. This one shows the existence.
Definition - you are displaying to the compiler, the exact working of such and such function. This one shows the innards and the existence.
Ah.. can I use an analogy like this?

Declaration: Mobile phone brand X
Definition: 3G, SMS, mobile gaming, mp3 music, organizer etc etc..

regalrohit • Aug 16, 2008
hi,in definition,variable space is allocated for variable and for some initial value.

In declaration only intenifies the type of variable for function.In simple word in definition memory space is allocated.
In declartion refer to the place where the variable nature is stated,no allocation is done.
for example

void show()\\"declaration"//
printf("singh is king");
void main();\\"definition"
void show();
clr scr();
shravya • Aug 17, 2008
Declaration of variable:
declaration - u can declare variables
eg:int a;
here variable 'a ' is declared as integer type that means u can store integers in variable a .
///ly if u decalre 'a' as char , you can store characters in a
eg: char a;
In functions function definition plays an imp. role .
void fun()//fun definition

that means here we r not declaring but instead we r writing some code in a function.
mata • Aug 17, 2008
hi friends........
Declaration - u r telling the compiler in advance dat u will be using that function in future. this include d data of the function and arguments
Defination - this means dat u r giving functionality or writig body for the function ,what actually a function is going to do
niraj.kumar • Aug 24, 2008
In C --- in declaration memory is not allocated
--- in definition memory get allocated

Share this content on your social channels -