Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
CPP All : Functions Reference Passing/Returning
Concept Learning Code Sheets
Check if string is a palindrome using a function. #1395 

Check if a character array or c-style string is same (Palindrome) when reversed using an independent function.

Call by reference demonstration #2647 

A simple call by reference demonstration by adding something in the original value itself.

Function Call by Reference and Call by Value comparison #2680 

A program that uses both call by reference and call by value in the same program to compare it for better understanding.

Variable swapping using function call by reference #2685 

Swapping (Interchange) of two variable values using the call by reference technique of function arguments.

Global and Local Function Declaration #2689 

Understanding global and local function declaration using a function declaration above main and another inside the main routine.

Passing null terminated string to function using array notation #2701 

Program to pass by reference character array as a null terminated string to a function using the array notation using [ ].

Passing null terminated string to function using pointer notation #2706 

Program to pass by reference character array as a null terminated string to a function using the pointer notation using *.

Passing integer array to a function for linear search #2733 

Program to pass an integer array, length of array and the member to be found to a function and return the position of the member found.

Changing multiple values of integer array passed to a function #2737 

A program to pass integer array to a function and change many values in it based on a condition. Then reading such values in the calling function.

Function returning by reference #2749 

A program to demonstrate returning of a reference data type from the function.

Using function return by reference to modify a global array #2754 

A program that neatly modifies a global array by using the function return by reference technique.

Solved Problems
Char array passing to function #2656 

Write a function alpha_count() where a character array is passed as reference and the length of array is passed as value. The output of function should be number of alphabets in the input array. You can use function isalpha() if you wish so.

Write a function alpha_count() where a character array is passed as reference and the len ...
Array to array data #2697 

Write output of the following code and explain its working.

Write output of the following code and explain its working. ...
Correcting error in function call by reference #2742 

Program given below has some incorrectly written function call, correct the mistake and rewrite the
program.

Program given below has some incorrectly written function call, correct the mistake and re ...
Setting bigger of two values using function returning reference #2757 

Write a c++ program using function returning the reference which finds the bigger of two variables
passed it and then it sets the bigger variable to 10 while it is called. Show its implementation by writing the main routine also.

Write a c++ program using function returning the reference which finds the bigger of two ...
First and last digit of an integer in a function and putting at reference location #3018 

Write a c++ program using a function with the following prototype –
void first_last_digit(int n,int first,int last);
In this function pass an integer number as n and then find the first and last digit of n. Then update it on locations first and last passed as reference. Assume values to be passed to demonstrate the working of this function in the main routine.

Write a c++ program using a function with the following prototype - void first_l ...
Output writing – Function – pass by reference #5197 

Find and write the output of the following C++ program code: Note : Assume all required header files are already included in the program.

void Revert(int &Num, int Last=2)
{
  Last=(Last%2==0)?Last+1:Last-1;
  for(int C=1; C<=Last; C++)
  Num+=C;
}

void main()
{
  int A=20,B=4;
  Revert(A,B);
  cout<<A<<"&"<<B<<endl;
  B--;
  Revert(A,B);
  cout<<A<<"#"<<B<<endl;
  Revert(B);
  cout<<A<<"#"<<B<<endl;
}
Find and write the output of the following C++ program code: Note : Assume all required he ...
Output Writing – Function Returning reference #5265 

Write output of the following code. Assume inclusion of related header files.

int &min(int &a, int &b)
{
  if (a<b) return a;
  else return b;
}

int main()
{
  int x=2,y=3;
  min(x,y)=10; 
  cout<<"x-y = "<<(x-y)<<endl;
  cout<<"y-x = "<<(y-x)<<endl;
  return 0;
}
Write output of the following code. Assume inclusion of related header files.
int &a ...		
Output Writing – passing integers as ref and as def value #5834 

Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .

void Position (int &C1, int C2=3)
{
  C1+=2;
  C2+=2;   //Original paper had this incorrectly written as Y
}
void main()
{
  int P1=20, P2=4;
  Position(P1);
  cout<<P1<<","<<P2<<endl;
  Position(P2,P1);
  cout<<P1<<","<<P2<<endl;
}
Write the output of the following C++ program code: Note: Assume all required header file ...
Output Writing – passing integers as ref and as def value #5935 

Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

void Location(int &X,int Y=4)
{
  Y+=2;
  X+=Y;
}
void main()
{
  int PX=l0,PY=2;
  Location(PY) ;
  cout<<PX<<","<<PY<<endl ;
  Location(PX,PY);
  cout<<PX<<","<<PY<<endl ;
}
Write the output of the following C++ program code: Note: Assume all required header file ...
Function arguments as pointer reference – Output writing #6953 

Find and write the output of the following C++ program code:

Note: Assume all required header files are already included in the program.

void Alter(char *S1, char *S2)
{
  char *T;
  T=S1;
  S1=S2;
  S2=T;
  cout<<S1<<"&"<<S2<<endl;
}
void main()
{
  charX[]="First", Y[]="Second";
  Alter(X,Y);
  cout<<X<<"*"<<Y<<endl;
}

 

Find and write the output of the following C++ program code: Note: Assume all required ...
Output Writing – passing integers as ref and as def value #7699 

Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

void series(int x=10)
{
  for(int i=2;i<=x;i+=2)
   cout<<i<<" ";
  cout<<endl; 
}
void modify(int &n)
{
  n*=2; 
  series(n);
}

int main()
{
   int a=10;
   cout<<"a="<<a<<endl;
   modify(a);
   series();
   cout<<"new a="<<a<<endl;
   return 0;
}
Write the output of the following C++ program code: Note: Assume all required header file ...
Exam Questions
CBSE12A-2018-01D  Output writing – Function – pass by reference #5197 

Find and write the output of the following C++ program code: Note : Assume all required header files are already included in the program.

void Revert(int &Num, int Last=2)
{
  Last=(Last%2==0)?Last+1:Last-1;
  for(int C=1; C<=Last; C++)
  Num+=C;
}

void main()
{
  int A=20,B=4;
  Revert(A,B);
  cout<<A<<"&"<<B<<endl;
  B--;
  Revert(A,B);
  cout<<A<<"#"<<B<<endl;
  Revert(B);
  cout<<A<<"#"<<B<<endl;
}
Find and write the output of the following C++ program code: Note : Assume all required he ...
CBSE12D-2015-01D  Output Writing – passing integers as ref and as def value #5834 

Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .

void Position (int &C1, int C2=3)
{
  C1+=2;
  C2+=2;   //Original paper had this incorrectly written as Y
}
void main()
{
  int P1=20, P2=4;
  Position(P1);
  cout<<P1<<","<<P2<<endl;
  Position(P2,P1);
  cout<<P1<<","<<P2<<endl;
}
Write the output of the following C++ program code: Note: Assume all required header file ...
CBSE12A-2015-01D  Output Writing – passing integers as ref and as def value #5935 

Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

void Location(int &X,int Y=4)
{
  Y+=2;
  X+=Y;
}
void main()
{
  int PX=l0,PY=2;
  Location(PY) ;
  cout<<PX<<","<<PY<<endl ;
  Location(PX,PY);
  cout<<PX<<","<<PY<<endl ;
}
Write the output of the following C++ program code: Note: Assume all required header file ...
CBSE12A-2019-A01D  Function arguments as pointer reference – Output writing #6953 

Find and write the output of the following C++ program code:

Note: Assume all required header files are already included in the program.

void Alter(char *S1, char *S2)
{
  char *T;
  T=S1;
  S1=S2;
  S2=T;
  cout<<S1<<"&"<<S2<<endl;
}
void main()
{
  charX[]="First", Y[]="Second";
  Alter(X,Y);
  cout<<X<<"*"<<Y<<endl;
}

 

Find and write the output of the following C++ program code: Note: Assume all required ...

Code Sheets:11  Solved Problems:14  Exam Questions:4 
Back