O
orca
Hi there
I would like to know exactly what is the distinction between a
declaration and a definition, with some simple but illuminating
examples for variables and functions, which I am somewhat more used
to; as I guess, some examples with more than one file (or translation
unit) might be expedient.
According to Stroustrup's "Programming Principles and Practice with C+
+", pages 51 and 61, a declaration is a "program statement specifying
how a piece of code can be used", whereas a definition is a "statement
that introduces a new name into a program and sets aside memory for a
variable". Thus, if I understand correctly, a declaration does not
assign memory to a named object, right? Also, I have read somewhere
that a definition is also always a declaration; is that correct??
Examples:
int num;
string name="John Doe";
are definitions.
int func(string, bool);
external double Pi;
are declarations; they do not (why??) set aside memory???
Thanks for any guidance
I would like to know exactly what is the distinction between a
declaration and a definition, with some simple but illuminating
examples for variables and functions, which I am somewhat more used
to; as I guess, some examples with more than one file (or translation
unit) might be expedient.
According to Stroustrup's "Programming Principles and Practice with C+
+", pages 51 and 61, a declaration is a "program statement specifying
how a piece of code can be used", whereas a definition is a "statement
that introduces a new name into a program and sets aside memory for a
variable". Thus, if I understand correctly, a declaration does not
assign memory to a named object, right? Also, I have read somewhere
that a definition is also always a declaration; is that correct??
Examples:
int num;
string name="John Doe";
are definitions.
int func(string, bool);
external double Pi;
are declarations; they do not (why??) set aside memory???
Thanks for any guidance