About changing data type in c and c++

Asked By 20 points N/A Posted on -
qa-featured

In programming language c or c++, is it possible to change data type of the field that already contains data?

SHARE
Answered By 0 points N/A #101483

About changing data type in c and c++

qa-featured

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.

.

Login/Register to Answer

Related Questions