CrazyEngineers
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • MaRo

    MemberAug 10, 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()
    {
    printf("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.
    Are you sure? This action cannot be undone.
    Cancel
  • banu

    MemberAug 11, 2008

    Both are based on functions and variables mostly.
    EXAMPLE
    For declaration

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

    For definition:
    void write()
    {
    printf("enter the name");
    scanf("%s",name);
    }
    Here the operation/function of write() is defined.
    definition must be given before declaration.
    i guess iam right
    Are you sure? This action cannot be undone.
    Cancel
  • Amit Saste

    MemberAug 11, 2008

    nishcom
    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
    sum=sum+a:
    }

    Hope u got it!!
    Are you sure? This action cannot be undone.
    Cancel
  • umesh936

    MemberAug 12, 2008

    hi
    Last one is correct(Amit)

    #include<stdio.h>
    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..
    Are you sure? This action cannot be undone.
    Cancel
  • mohanapriya

    MemberAug 12, 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 technical....so please guide me ...
    Are you sure? This action cannot be undone.
    Cancel
  • Mrunalini

    MemberAug 12, 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:
    <Return type> <Function Name>(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:

    <Return Type> <Function Name>(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.. 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Prasad Ajinkya

    MemberAug 12, 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.
    Are you sure? This action cannot be undone.
    Cancel
  • Ashraf HZ

    MemberAug 13, 2008

    Ah.. can I use an analogy like this?

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

    😛
    Are you sure? This action cannot be undone.
    Cancel
  • regalrohit

    MemberAug 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");
    }
    #include<stdio.h>
    void main();\\"definition"
    {
    void show();
    clr scr();
    show();
    getch();
    }
    Are you sure? This action cannot be undone.
    Cancel
  • shravya

    MemberAug 16, 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;
    Definition:
    In functions function definition plays an imp. role .
    EG:
    void fun()//fun definition
    {
    printf("thanx");
    }

    that means here we r not declaring but instead we r writing some code in a function.
    Are you sure? This action cannot be undone.
    Cancel
  • mata

    MemberAug 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 type.name 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
    Are you sure? This action cannot be undone.
    Cancel
  • niraj.kumar

    MemberAug 23, 2008

    In C --- in declaration memory is not allocated
    --- in definition memory get allocated
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register