0

Sorry in advance for possible duplicate. I learned that declaration puts a variable as "a thing" that is available in the code, definition would be something that is either initialized or not, for example int foo = 0 or

void function() {

}

would be defined, but not initialized, since foo practically does nothing since it has 0 assigned and function has opened curly braces, so both of them do take up memory. And something like int foo = 5 would be initialized since it stores number 5. Did I get it right? Sorry for possibly bad formating as well.

1 Answers1

1

When you put

int foo = 0;

You are assigning a number to foo so foo is initialized here if you don't want to initialize foo, You have to say

int foo;

For functions is like this too

void function(); // declare

void function(){

} // initialize
AriaN
  • 329
  • 1
  • 8
  • 1
    Interesting sidenote: For classes with user-declared constructors, it's pretty much impossible to declare them without defining them. – Mooing Duck Dec 15 '20 at 21:33