In this blog I will tell you some common differences between
value types and reference types.
1)
Value types are those type of data type which
will store value and reference type are those type of data type which will
store addresses of variable rather than value.
2)
Value types are stored in stack part of memory
while reference types are stored in heap part of memory.
3)
The default value which is initialized in value
types are 0, false, ‘\0’ etc while in reference types the default value are initialize
is null.
4)
When we assign the value of one value type
variable to another type of variable then it simply copy value of variable and
when we use assignment operator in case of reference variable then it copy
address of variable rather than value.
5)
Following example represent value type variable.
int i=17; int j=I;
Following example will represents
use of reference variable.
String sMessage=”Hello World”;
String sMessage1=sMessage;