hi friends,
check this program beneath.......

\\program to fin integere part and fractional part of given real number...
void intfrac(int,float&,float&);
void main()
float number,intpart,fracpart;
cout<<"enter any real number:";
cout<<"integer part is:"<<intpart;
cout<<"\nfraction part is:"<<fracpart;
void intfrac(float n,float& intp,float& fracp)

i was doing this program in order to implement the concept of passing the
value by reference in functions.
this can be done easily by using type casting,bt i was trying this logic......
but compiler is showing some errors (fracp=n%1;)in this line.
can someone help me with it........plz
also if someone can give some good points about the diff. between pass by reference
and pass by value......

6 Years
Discussion Span
Last Post by sahil1991

Actually, the float type doesn't support modulus operator. That is why your program is giving an error. It is because the float numbers are stored in memory in two parts, mantissa and exponent.
Now, if you understand the concept of pointers than try to understand this.
When we call a function by value, we call it like


. This passes to the function the values pointed to by these variables 'a' and 'b'.This creates a temporary image of these values in the memory somewhere for the function to work upon and thus the original variables are not affected at all.
But when we call a function by reference, we call it like


. Where '&a' and '&b' refer to the address of the variables stored in the memory. So, we pass to the function, the address values of the same variables. This unlike previously, makes the function operate on the same variables using their addresses. (NO temporary variables are made).
Hope you understood.!;):)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.