data definition and data declaration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimhakans
    New Member
    • Sep 2007
    • 41

    #1

    data definition and data declaration

    What is difference between "data definition" and "data declaration"?
  • kittu513
    New Member
    • Nov 2007
    • 3

    #2
    A declaration establishes the names and characteristics of data objects used in a program. A definition allocates storage for data objects, and associates an identifier with that object. When you declare or define a type, no storage is allocated...

    for more info check
    http://publib.boulder. ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic =/com.ibm.xlcpp8l .doc/language/ref/data_dec.htm

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by kittu513
      When you declare or define a type, no storage is allocated...
      Not true.

      When you declare a type no storage is allocated.

      When you define a type, then storage is allocated.

      You said it yourself in the previous sentence and then seemed to contradict yourself. Probable just a typo but I wanted to be sure the OP was not misled.

      Comment

      • jimhakans
        New Member
        • Sep 2007
        • 41

        #4
        Originally posted by weaknessforcats
        Not true.

        When you declare a type no storage is allocated.

        When you define a type, then storage is allocated.

        You said it yourself in the previous sentence and then seemed to contradict yourself. Probable just a typo but I wanted to be sure the OP was not misled.
        Thanks 4 that.
        but can u plz give me exp like
        int a=0;
        this is included in definition right and
        int a;
        this is a declaration that ur identifier is of integer type?

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by jimhakans
          but can u plz give me exp like
          int a=0;
          this is included in definition right and
          int a;
          this is a declaration that ur identifier is of integer type?
          int a = 0; is a definition. Memory is allocated. The value of the int is 0.

          int a; is a definiton. Memory is allocated. The value of the int is garbage.

          A declaration of than integer requires that no memory be allocated. The only way that can happen is if the int is in some other source file. In that case you can declare an int:

          extern int a;

          The compiler will report the int as an unresolved external reference. This will cause the linker to go find the int and connect it to the code in this source file.

          Comment

          Working...