I guess that a declaration can be a definition, 
since it is one in the same, true
int x; //declaration 
int x = 5;  //declaration and definition


Brett McCoy <[EMAIL PROTECTED]> wrote:                               On Feb 17, 
2008 8:36 PM, Robert Ryan <[EMAIL PROTECTED]> wrote:
 
 > what is the difference between a declaration and a definition in C++.
 > can a declaration be a definition........ does a declaration just give a 
 > type, but a definition gives a type and reserves memory location    int a; - 
 > a declaration
 > int a =2; a definition
 
 A declaration is a statement that show you intend to use a variable,
 although it may be *defined* somewhere else.
 
 Defining a variable means you have assigned an initial value to it.
 For most types of variables, even if you have declared them, you can't
 use them until you give them an initial value.
 
 A declaration and a definition can be done at the same time for some
 variables. In C, you can only declare a variable at the beginning of
 scope. In C++, you can declare a variable anywhere inside a scope;
 although I tend to still declare all of my variables at the beginning
 of a scope just because it's all done in one place and it's neat and
 tidy. Loop variables are the exception.
 
 Sometimes the definition of a variable is done outside the current
 scope (even file scope), but you still need to declare the variable
 before you use it (like for extern variables defined in another
 module). Many times the declaration of global variables like this are
 done in a header file.
 
 -- Brett
 ----------------------------------------------------------
 "In the rhythm of music a secret is hidden;
     If I were to divulge it, it would overturn the world."
                -- Jelaleddin Rumi
 
     
                               

       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.

[Non-text portions of this message have been removed]

Reply via email to