0% found this document useful (0 votes)
4 views

notes_on_function_refrence

The document contains a series of C programs that demonstrate the use of reference parameters and their effects on variable values. Each program is followed by its expected output, illustrating how the calculations and modifications to variables occur through function calls. The outputs show the final values of the variables after executing the functions with different inputs.

Uploaded by

Sanjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

notes_on_function_refrence

The document contains a series of C programs that demonstrate the use of reference parameters and their effects on variable values. Each program is followed by its expected output, illustrating how the calculations and modifications to variables occur through function calls. The outputs show the final values of the variables after executing the functions with different inputs.

Uploaded by

Sanjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Determine the output of the following program

#include<stdio.h>
#include<conio.h>
void calculate(int &x,int y)
{
x=x*y+2*(x+y);
y=x/y+(x+y)/2;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=2, b=4;
calculate(a,b);
printf("\n a=%d, b=%d",a,b);
calculate(b,a);
printf("\n a=%d, b=%d",a,b);

}
Output
x=20, y=17
a=20, b=4
x=128, y=80
a=20, b=128
2. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
void calculate(int &x,int y)
{
x=y*2+x;
y=x-y;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=3, b=5;
calculate(a,b);
printf("\n a=%d, b=%d",a,b);
calculate(b,a);
printf("\n a=%d, b=%d",a,b);
}
Output
x=13, y=8
a=13, b=5
x=31, y=18
a=13, b=31
3. Determine the output of the following program.
#include<stdio.h>
#include<conio.h>
void calculate(int x,int &y)
{
x=x+y;
y=x+y;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=3, b=5;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);

}
Output
x=8, y=13
a=3, b=13
x=16, y=19
a=19, b=13

4. Determine the output of the following program.


#include<stdio.h>
#include<conio.h>
void calculate(int x,int &y)
{
x=x-y;
y=x-y;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=5, b=3;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);

}
Output
x=2, y=-1
a=5, b=-1
x=-6, y=-11
a=-11, b=-1
5. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
void calculate(int x,int &y)
{
x=x/y+1;
y=y%x+1;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=5, b=3;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);

}
Output
x=2, y=2
a=5, b=2
x=1, y=1
a=1, b=2
6. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
void calculate(int x,int &y)
{
if(x>y)
y=y*y;
else
x=(x+y)/2;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=5, b=3;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);
}
Output
x=5, y=9
a=5, b=9
x=9, y=25
a=25, b=9
7. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
void calculate(int x,int &y)
{
if(x%y==0)
x=y;
else
y=x;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=5, b=2;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);
}
Output
x=5, y=5
a=5, b=5
x=5, y=5
a=5, b=5
8. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
void calculate(int x,int &y)
{
if(x/y==0)
y=10*y;
else
x=5*x;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=5, b=2;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);
}
output
x=25, y=2
a=5, b=2
x=2, y=50
a=50, b=2
9. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
void calculate(int &x,int &y)
{
if(x/y==0)
y=5*y;
else
x=3*x;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=3, b=2;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);
}
Output
x=9, y=2
a=9, b=2
x=2, y=45
a=45, b=2
10.Determine the output of the following program.
#include<stdio.h>
#include<conio.h>
void calculate(int &x,int &y)
{
if(y%2!=0)
y=y-1;
if(x%2!=0)
x=x+1;
printf("\nx=%d, y=%d",x,y);
}
main()
{
clrscr();
int a=13, b=15;
calculate(a,b);
printf("\na=%d, b=%d",a,b);
calculate(b,a);
printf("\na=%d, b=%d",a,b);
}
Output
x=14, y=14
a=14, b=14
x=14, y=14
a=14, b=14

You might also like