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.

Exam Paper Problems

Output writing – Function – pass by reference #5197

( As In Exam - CBSE12A-2018 )

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

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;
}

Output Writing – passing integers as ref and as def value #5834

( As In Exam - CBSE12D-2015 )

Write the output of the following C++ program code:
Note: Assume all re

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;
}

Output Writing – passing integers as ref and as def value #5935

( As In Exam - CBSE12A-2015 )

Write the output of the following C++ program code:
Note: Assume all re

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 ;
}

Function arguments as pointer reference – Output writing #6953

( As In Exam - CBSE12A-2019 )

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

Note: Ass

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;
}

 

Solved Problems

output writing, pass by ref/pass by value #2652

Write the output of the following code piece.

Write the output of the following code piece.

Char array passing to function #2656

Write a function alpha_count() where a character array is passed as reference

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.

Output writing – passing string as char pointer #2659

Write output of the following code.

Write output of the following code.

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.

Output writing function within function with array passing #2746

Dry run the following program carefully and write the output.

Dry run the following program carefully and write the output.

Correcting error in function call by reference #2742

Program given below has some incorrectly written function call, correct the m

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

Setting bigger of two values using function returning reference #2757

Write a c++ program using function returning the reference which finds the b

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.

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 –

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.

Output Writing – Function Returning reference #5265

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

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;
}

Output Writing – passing integers as ref and as def value #7699

Write the output of the following C++ program code:
Note: Assume all re

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;
}

Code Sheets:11  Exam Paper Problems:4  Solved Problems:10 
×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back