What is the difference between declaration and definition?

Showing Answers 1 - 10 of 10 Answers

Xing

  • Sep 13th, 2007
 

In case of C Functions.

Declaration: When we write the prototype of the function before using it, this is called function declaration.

Definition: When we define code for the function with the function name itself, it is called function definition.

  Was this answer useful?  Yes

DECLARATION : declaration only creates the variable name and nothing exists against it. i.e no memory space is consumed.

eg. extern a;

DEFINITION : definition declares as well as assigns some value to the variable.

eg.  int a;

even though we are not mentioning any value default value is provided by the C compiler.

eg. int a=10;

  Was this answer useful?  Yes

jontyrodes

  • May 9th, 2008
 

Definition
int * i
i is definitionsince we can store a address without allocating memory
*i is definition since we can assign *i = 4 ;

Definition
char *c
c is definition since it can store a address of a character
*c is definition since it can store a character
Now, c is a declaration for storing a string, now i need to allocate memory to store a string..

Comments anyone ???

  Was this answer useful?  Yes

ashok reddy chenikala

  • Aug 31st, 2011
 

Declaration means just identify the datatype and some memory allocation. If we print the value it gives garbage value.

Definition means declaration and assign some value to that variable. i.e. definition = declaration + initialization.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions