Definition and declaration

Status
Not open for further replies.

anshu

Solid State Member
Messages
17
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.
 
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.
 
Status
Not open for further replies.
Back
Top Bottom