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

\\program to fin integere part and fractional part of given real number...
#include<iostream.h>
#include<conio.h>
void intfrac(int,float&,float&);
void main()
{
float number,intpart,fracpart;
cout<<"enter any real number:";
cin>>number;
intfrac(number,intpart,fracpart);
cout<<"integer part is:"<<intpart;
cout<<"\nfraction part is:"<<fracpart;
getch();
}
void intfrac(float n,float& intp,float& fracp)
{
fracp=n%1;
intp=n-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......

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

func(a,b)

. 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

func(&a,&b)

. 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.!;):)

thanx,this helped a lo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.