简体   繁体   中英

Operations on different data types

When i was dividing a int variable with a float variable, it was giving correct answer. I thought data types needed typecasting to be, for one data type cant operate with another kind of data type. If not, then how does the processor decide it can operate int and float, but not int and char.

In cases where you have not explicitly typecast the variables, implicit typecasting is performed. An example of how implicit typecasting works :

int variable = (int / float ) -> variable will have an integer value.

float variable = (int / float ) -> variable will have a float value.

An example using char and int :

int a=0; 
char c='c'; 
a = c; 
cout<<"Ascii value of"<<c<<"is "<<a; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM