From what I’m able to understand:

  • declaration is when prototype or declaration is used to describe the features
  • definition is when a declaration is also assigned a literal or an object
  • initialization is the assignment of an object, either during definition or immediately after declaration
  • assignment is the setting of a value of a particular object

Which of the follow terms overlap? Which of them is a superset/subset of each other?

  • aMockTie@beehaw.org
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    I would define them as follows:

    • Declaration: This thing exists.
    • Definition: Here are the details for how this thing works.
    • Initialization: Assign the initial state to this thing.
    • Assignment: The value of this thing is now X.
  • Manucode@feddit.de
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    My understanding:

    int a = 1;
       // variable definition =
       // declaration + initialisation
    
    int b; // variable declaration
    
    b = 2  // variable initialisation,
           // type of assignment
    
    a = 3  // variable assignment
    
    int f(int x, int y);
       // function declaration
    
    int g(int z) {
       return z;
    }  // function definition
    
    int f(int x, int y) {
       return x + y;
    }  // function definition