About changing data type in c and c++
In programming language c or c++, is it possible to change data type of the field that already contains data?
In programming language c or c++, is it possible to change data type of the field that already contains data?
No, It is impossible. As you can see that whenever you are entering data to a variable, it gets converted into binary form. If you want to lower the number of bytes allocated then the value gets our of order. However you can do the following.
Type Casting is a main issue where you are working with different type os data that are interlinked with each other, However loss of precession should always be considered.
int i;
float j=33.4;
i = ( int ) j;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // the value after decimal part is lost.
j = ( float ) i                 // no data is lost as the float data type is larger than the int data type
You can use templates to allow a single function to accept multiple variables of different datatypes. This is possible. The main motive is that use another variable for the new requirement.
.