Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Definition and declaration
Closed Thread
Old 07-07-2005, 08:49 AM   #1 (permalink)
 
Newb Techie

Join Date: Apr 2005

Posts: 17

anshu is on a distinguished road

Default Definition and declaration

hey,
Can anyone tell me,what's the difference between

declaration and definition in C++.my teacher in the college

couldn't explain this properly to me as he himself was not sure

about it, and we had a good arguement over this.

thank you.
anshu is offline  
Old 07-07-2005, 08:57 AM   #2 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

When you define something you describe it. This mainly applies to functions, methods, classes, structs, though it can also apply to variables. When you declare something, you're basically saying, "Look here, I've got [X] which is of type [Y], so be forewarned!"

Example:

Declaration:
Code:
int i;
Definition:
Code:
i = 240;
See, when you declare something, you're kind of giving the compiler a fore-warning about that type. When you define something, you're actually giving it a value, and defining it.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
 
Closed Thread

Thread Tools
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

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