Well for functions when you declare a function you specify its name and type as well as what parameters it accepts at the beginning. When you define a function the function is actually typed out as to what it does.
In a class the variable follows the same rule where in a class definition the declaration of a variable takes no memory until a instance of the class is defined.
I tend to separate pure variables in a function by calling them declared or initialized.
Declared takes memory but the data of the variable is garbage.
Initialized is declared but the data has been defined in some fashion, either by the user or some operation in the program.
Putty is not a compiler. Chances are whatever compiler you're using is being nice.
What is Debug and release mode?
These you would set when using an IDE such as Code::Blocks or Visual Studio. In Debug mode, compiler optimizations are turned off, and new memory is set to zero (at least with Visual Studio), among other things. In Relase mode, compiler optimizations are turned on, among other things. Despite the name, it is possible to debug in Release mode. If you're not using an IDE, you can achieve the same Debug/Release effect by having a set of compiler flags for "Debug" and a another set for "Release".
When I run the above code with Visual Studio 2005, I get -842150451 in Debug mode, and 24 in Release mode. These numbers depend on what happened to be in that memory location at the time.
When I run the above code with Visual Studio 2005, I get -842150451 in Debug mode, and 24 in Release mode. These numbers depend on what happened to be in that memory location at the time.
That is what I expected to happen at first. I am not sure how/why putty is initializing the variables.
Prior to starting this thread, I ran a program similar to what you gave above, except I declared an array of variables instead of a pointer to one variable. Be it integers, doubles or chars, the value of the elements in the array were always uniform (zero, zero, empty).
However, the values were not uniform when I declared a pointer to one variable and indexed it:
1 2 3
int* aa;
for (int i = 0; i < 10; ++i)
cout << aa[i] << endl;
. This lead me to believe the new operator was initializing the variables somehow.
Essentially, it comes down to undefined behaviour. Reading from an uninitialized automatic variable (such as a local variable on the stack) is undefined (could be garbage, or zero). Same deal for reading from uninitialized memory that's been dynamically created (the value depends on what is in that memory location at the time), i.e. it's indeterminate.
And to (hopefully) unconfuse, here's what the standard (2003) says:
(5.3.4.15) If the new-initializer is of the form (), the item is value-initialized (8.5)
(8.5.5) To value-initialize an object of type T means: (in our case) the object is zero-initialized
(8.5.5) To zero-initialize an object of type T means: if T is a scalar type (3.9) (as in our case), the object is set to the value of 0 (zero) converted to T;