CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | Be a CE Ambassador! | Forgot password? | Sponsor CE | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  #1 (permalink)
Old 11th August 2008, 01:42 AM
CE - Newbie
 
I'm a Crazy Information Technology Engineer
Join Date: 15th June 2008
Posts: 8
Default Definition and declaration

Would anyone please tell me what is the difference between Declaration and Definition in "c"?
nishcom is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 11th August 2008, 01:38 PM
Moderator
 
MaRo's Avatar
 
I'm a Crazy Computer Engineer
Join Date: 2nd May 2007
Location: Egypt
Posts: 259
Send a message via MSN to MaRo
Default Re: Definition and declaration

they're about the look of the function in a program

Definition is writing the function and how it is working like
Code:
void foo()
{
printf("foo");
}
Declaration is just writing the function header to implement in another function like:
Code:
int main()
{
foo(); // this is declaration
return 0;
}
And of course to write a declaration there should be a definition to implement.
MaRo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 11th August 2008, 09:02 PM
CE - Apprentice
 
I'm a Crazy information technology Engineer
Join Date: 28th July 2008
Posts: 10
Default Re: Definition and declaration

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
banu is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 12th August 2008, 11:55 AM
CE - Newbie
 
I'm a Crazy Computer Science Engineer Engineer
Join Date: 11th August 2008
Posts: 6
Default Re: Definition and declaration

Quote:
Originally Posted by nishcom View Post
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[i]:
}

Hope u got it!!
Amit Saste is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)
Old 13th August 2008, 02:38 AM
CE - Newbie
 
umesh936's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 26th November 2006
Posts: 9
Default Re: Definition and declaration

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..
umesh936 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)
Old 13th August 2008, 01:10 PM
CE - Newbie
 
I'm a Crazy computer Engineer
Join Date: 12th August 2008
Posts: 5
Default Re: Definition and declaration

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 ...
__________________
priya
mohanapriya is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)
Old 13th August 2008, 02:27 PM
CE - Apprentice
 
Mrunalini's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 8th August 2008
Location: Pune, India
Posts: 14
Send a message via Yahoo to Mrunalini
Default Re: Definition and declaration

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..
__________________
Regards,
Mrunalini
Mrunalini is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)
Old 13th August 2008, 05:26 PM
CEan - Value Adder
 
kidakaka's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 18th October 2006
Location: Mumbai, Hyderabad
Posts: 465
Send a message via AIM to kidakaka Send a message via MSN to kidakaka Send a message via Yahoo to kidakaka Send a message via Skype™ to kidakaka
Default Re: Definition and declaration

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.
kidakaka is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)
Old 13th August 2008, 05:39 PM
ash
Moderator
 
ash's Avatar
 
I'm a Crazy Communications Engineer
Join Date: 12th July 2007
Location: IIUM, Malaysia
Posts: 1,506
Default Re: Definition and declaration

Ah.. can I use an analogy like this?

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

__________________
Keep it simple. Keep it real.
| New to CE? Click here! | Join our CE Bot project! | Problems? Questions? PM or mail me at ash{at]crazyengineers{dot]com |
ash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)
Old 17th August 2008, 03:09 AM
CE - Newbie
 
I'm a Crazy COMPUTER SCIENCE Engineer
Join Date: 17th August 2008
Posts: 1
Default Re: Definition and declaration

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();
}
regalrohit is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 10:00 PM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger