What is the difference between the declaration and the definition of a variable

What is the difference between the declaration and the definition of a variable?
The definition is the one that actually allocates space, and provides an initialization value, if any.
There can be many declarations, but there must be exactly one definition. A definition tells the compiler to set aside storage for the variable. A declaration makes the variable known to parts of the program that may wish to use it. A variable might be defined and declared in the same statement.



Also read the more C interview questions

  1. Do Global variables start out as zero? 
  2. Does C have boolean variable type?
  3. Where may variables be defined in C?
  4. To what does the term storage class refer? What are auto, static, extern, volatile, const classes?
  5. What does the typedef keyword do?
  6. What is the difference between constants defined through #define and the constant keyword?
  7. What are Trigraph characters?
  8. How are floating point numbers stored? Whats the IEEE format?
  9. When should a type cast be used?
  10. Can structures be assigned to variables and passed to and from functions?

No comments:

Post a Comment