this post was submitted on 10 Jan 2024
3 points (100.0% liked)

General Programming Discussion

7831 readers
1 users here now

A general programming discussion community.

Rules:

  1. Be civil.
  2. Please start discussions that spark conversation

Other communities

Systems

Functional Programming

Also related

founded 5 years ago
MODERATORS
3
(lemmy.ml)
submitted 10 months ago* (last edited 10 months ago) by velox_vulnus@lemmy.ml to c/programming@lemmy.ml
 

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, such that a chunk of memory is allocated
  • 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 at any stage of the program execution

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

top 2 comments
sorted by: hot top controversial new old
[โ€“] manucode@feddit.de 2 points 10 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
[โ€“] aMockTie@beehaw.org 1 points 10 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.