My First Programming with C++ : Function

I am learning C++ . Last class i had learned Function . Code :

#include<iostream.h>

double data_type(double x,double y)

{
    double z;
    z=x+y;
    return z;

}

int main ()

{

    double a;
    a=data_type(5.8,5.6);
    cout<<a<<“n”<<“……..n”;

    return 0;

}

You will get the result 11.4 . But if you change data type :

Function C++

If you change the red marked data type to integer or int , any of those three or all , result will be : 11

But if you change green marked data type to integer or int , both of them , result will be : 10

Are you getting the idea ? whenever you change the red marked data type to integer , it will show you the result having integer of result . That means , let result is 11.4 . It will show you 11 .

Whenever you change the green marked data type to integer , it will take the integer data of those given value . Above , I have given two value , x=5.8 & y=5.6 . When i change x’s green marked data type , it will take 5 out of 5.8 . And if i change y’s green marked data type , it will take 5 out of 5.6 . So the result will be : 10 .

If x’s green marked data type change to integer and all red marked data types are double or float then the result will be : 10.6

But if any red marked data types change to integer  than that result will be : 10

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.