answersLogoWhite

0

//This program swaps the values in the variable using function containing reference arguments

#include<iostream.h>

void swap(int &iNum1, int &iNum2);

void main()

{

int iVar1, iVar2;

cout<<"Enter two numbers "<<endl;

cin>>iVar1;

cin>>iVar2;

swap(iVar1, iVar2);

cout<<"In main "<<iVar1<<" "<<iVar2<<endl;

}

void swap(int &iNum1, int &iNum2)

{

int iTemp;

iTemp = iNum1;

iNum1 = iNum2;

iNum2 = iTemp;

cout<<"In swap "<<iNum1<<" "<<iNum2<<endl;

}

Reference arguments are indicated by an ampersand (&) preceding the argument:

int &iNUm1;

the ampersand (&) indicates that iNum1 is an alias for iVar1 which is passed as an argument.

The function declaration must have an ampersand following the data type of the argument:

void swap(int &iNum1, int &iNum2)

The ampersand sign is not used during the function call:

swap(iVar1, iVar2);

The sample output is

Enter two numbers

12

24

In swap 24 12

In main 24 12

------------------------------------------------------------------

By Satish from here

/ * Program to Swap Two Numbers by Using Call By Reference Method * /

#include

main()

{

int i, j;

clrscr();

printf("Please Enter the First Number in A : ");

scanf("%d",&i);

printf("\nPlease Enter the Second Number in B : ");

scanf("%d",&j);

swapr(&i,&j); /* call by reference*/

printf("A is now in B : %d",i);

printf("B is now in A : %d",j);

}

/* call by reference function*/

swapr(int *x, int *y)

{

int t;

t=*x;

*x=*y;

*y=t;

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Program to exchange the value x and y using 3 variables?

temp = x; x = y; y = temp;


Which variable is not destroyed on exit from the function instead its value is presented and becomes available again when the function is next called These variables are declared as?

Local function variables defined static remain in memory at all times. Such variables are only in scope (accessible) when the function itself is in scope.


What module returns a value back to the part of the program that called it?

A function. You can have a function that returns but doesn't return a value with it.


Write a program that defines a template function named add This function takes two arguments add two variables and then return the sum?

Write a program that defines a template function named add(). This function takes two arguments, add two variables and then return the sum. In main function, define two variables of type int, two variables of type float and two objects of type 'String'. Now call the add() function three times for these different data types. Note: String is a user-defined data type and for this you have to define a class named 'String'. When template function will be called to add two objects of type String then it must concatenate two strings. Your output should look like this: Sample Output: Enter two integer values to be added Enter First value: 12 Enter Second value: 25 Enter two float values to be added Enter First value: 13.5 Enter Second value: 14.2 Enter two Strings to be added Enter First value: Virtual Enter Second value: University Addition of two variables of different data types Sum of values of type int = 37 Sum of values of type float = 27.7 Sum of values of type String = VirtualUniversity


Variable Is a location in the computer's memory where a value can be stored for use by a?

program. Each variable has a name that serves as an identifier, allowing the program to reference and manipulate the stored value. Variables can hold different types of data, such as integers, strings, or booleans, and their values can be changed throughout the program's execution. This flexibility makes variables essential for managing data and controlling the program's behavior.

Related Questions

What are independent variables and dependent variables in math?

Independent variables are the input value of a function (usually x) and dependent variables are the output value of the function (usually y).


Program to exchange the value x and y using 3 variables?

temp = x; x = y; y = temp;


When can we say that a function is a relation?

When it doesn't fulfill the requirements of a function. A function must have EXACTLY ONE value of one of the variables (the "dependent variable") for every value of the other variable or variables (the "independent variable").


When can we say that a relation is a function?

When it doesn't fulfill the requirements of a function. A function must have EXACTLY ONE value of one of the variables (the "dependent variable") for every value of the other variable or variables (the "independent variable").


What is the minimum value of the function u(x, y) when considering both x and y as variables?

The minimum value of the function u(x, y) occurs at the point where the function reaches its lowest value when both x and y are considered as variables.


To evaluate a function for a specific value substitute the value in for what?

You substitute the variable for its value. Or you substitute the variables for each of the values.


Which variable is not destroyed on exit from the function instead its value is presented and becomes available again when the function is next called These variables are declared as?

Local function variables defined static remain in memory at all times. Such variables are only in scope (accessible) when the function itself is in scope.


What mean by reference function in c?

Reference function has no meaning. Variables are passed to functions by reference or by value, depending on the function signature.


What is the expression for finding the minimum value of a function in terms of the variables g and l?

The expression for finding the minimum value of a function in terms of the variables g and l is typically written as f(g, l) minf(g, l).


What module returns a value back to the part of the program that called it?

A function. You can have a function that returns but doesn't return a value with it.


What is the difference between high and maxinum in Excel?

Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.Maximum is the highest value in a range of values and can be got using the MAX function. There is no function called High in Excel.


How do you evaluate in mathematics?

Evaluate means find the value of.To evaluate an expression, if there are any variables replace them by their values. Then, using BIDMAS/PEMDAS, calculate the value of the expression.Evaluate means find the value of.To evaluate an expression, if there are any variables replace them by their values. Then, using BIDMAS/PEMDAS, calculate the value of the expression.Evaluate means find the value of.To evaluate an expression, if there are any variables replace them by their values. Then, using BIDMAS/PEMDAS, calculate the value of the expression.Evaluate means find the value of.To evaluate an expression, if there are any variables replace them by their values. Then, using BIDMAS/PEMDAS, calculate the value of the expression.