+ 1
About Destructive
My teacher is said that if I do that: int sum; sum=5; //initialize sum=6; //destructive The second assignment process is called destructive. But when I looked programming book, it says that when you assign a value to a variable, you did the destructive process. It says variables have default value. I confused. Can anyone tell me what is the truth?
4 Answers
+ 1
when you assign a value to a variable, WHICH HAS VALUE
in C (and C++) variable hasn't default value, you should initialize it first.
For example, in Pascal integer variable has default value 0
+ 1
A variable has a default value. But it is not a defined value like 0 or "", it is rather the way the memory was when a space was allocated (by your computer, not you, in the stack) to hold your variable
+ 1
Someone says it has a default value, someone says has not ... But what I see is that when I print the value of a variable I am getting memory adress of my variable in C++, but in C I am getting. Anyway I confused.
+ 1
The state of the memory is not changed when you define a variable, so the variable contain what the memory had before.