Definition and declaration

Would anyone please tell me what is the difference between Declaration and Definition in "c"?


  • MaRo
    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
    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
    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
    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
    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
    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
    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.
  • Ashraf HZ
    Ashraf HZ
    Ah.. can I use an analogy like this?

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

  • regalrohit
    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
    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
    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
    In C --- in declaration memory is not allocated
    --- in definition memory get allocated

You are reading an archived discussion.

Related Posts

Name; Chad Fuller Trade; Aircraft Engineer Location; Queensland, Australia Occupation; Aircraft overhaul technition Hobbies; Jet propulsion, See Below! Why I joined; Why not? Shared knowledge is a good thing! This...
Ok, I know its really just a flashy way of saying PulseJet engine! But I had to start somewhere, I have just joined CE and wanted to throw a couple...
I am a starter in EEE.. Just doing my undergraduate course.. Can u pls give me some papers for my presentation.. I need to present some technical papers.. Pls help...
Large Hadron Collider (LHC) is going to be started on 10th Sept 2008. Its prepared by CERN (Europian Organization for Nuclear Research). Read the news here... CERN - The Large...
hello, i need some topics for projects in mechanical engineering field