21 Nov 2019

  • November 21, 2019
  • Amitraj
Implicit Conversions:-

 we can mix data types in expressions.
 for example: 

                            m= 5+2.75;

is a valid statement.  whenever data types are mixed in an expression, C++ performs the conversion automatically.
 This process is known as Implicit or Automatic conversion.



#include<iostream>
using namespace std;
int main()
{
      int a=3;
       float b;
   int x=5; y=2;
       float z;
    b= a+3.56;      // Implicit
   
    z= x/ (float)y;  // Explicit  ( float(y) in C++ )
      cout<< b <<" ";
    cout<<z;
    return 0;
}

OUTPUT:

6.56       2.5

Translate

Popular Posts