01-04-2012, 10:28 PM
call by value
call by reference
call by pointer
Call by Value: When passing data by value, the data is copied to a local variable/object in the function. Changes to this data are not reflected in the data of the calling function. For larger objects, passing data by value can be very expensive.
Example:
void by_value(int a)
{
a+=10;
}
Call by Reference:When passing data by reference, a pointer to the data is copied instead. Changes to the data pointed to by the pointer are reflected in the data of the calling function. Regardless of the size of the object, passing data by reference always has the same cost.
Example:
void by_ref2(int &a)
{
a+=10;
}
Call by Pointer: When passing parameters to functions, the difference between references and pointers is that pointers can be null whereas references cannot. Pointers are preferred if null is a valid parameter value or if there is no alternative. Otherwise use const or non-const references.
Example:
void by_ref(int *a)
{
(*a)+=10;
}
call by reference
call by pointer
Call by Value: When passing data by value, the data is copied to a local variable/object in the function. Changes to this data are not reflected in the data of the calling function. For larger objects, passing data by value can be very expensive.
Example:
void by_value(int a)
{
a+=10;
}
Call by Reference:When passing data by reference, a pointer to the data is copied instead. Changes to the data pointed to by the pointer are reflected in the data of the calling function. Regardless of the size of the object, passing data by reference always has the same cost.
Example:
void by_ref2(int &a)
{
a+=10;
}
Call by Pointer: When passing parameters to functions, the difference between references and pointers is that pointers can be null whereas references cannot. Pointers are preferred if null is a valid parameter value or if there is no alternative. Otherwise use const or non-const references.
Example:
void by_ref(int *a)
{
(*a)+=10;
}
0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
