Categories
Computer Science / Information Technology Language: C

Functions and Recursion

Introduction to Functions

A function is a self-contained block of statements that perform a coherent task of some kind. Every C program can be thought of as a collection of these functions. In other words, a function is a block of code with a name and statements in it and is supposed to execute a particular task. A task could be anything which the programmer
desires. Consider the following example:

#include <stdio.h>
foo ( ) 
{
   printf("In foo function!\n") ;
}
int main ( ) 
{
    foo ( );
    printf ( "In the main function" ) ;
    return 0;
}

output:

In foo function!
In the main function

Note: The programs defined here might throw warnings when run. Just assume that the programs are correct for the time being. The warnings will be dealt with once we reach the function declaration and prototype topic.


The main( ) itself is a function and through it, we are calling the function foo( ). The word ‘call’ means that the control passes to the function foo( ). When the foo( ) function runs out of statements to execute, the control returns to main( ) and resumes executing its code at the exact point where it left off. Thus, main( ) becomes the ‘calling’ function, whereas foo( ) becomes the ‘called’ function.

Consider the following example:

#include <stdio.h>
hyderabad( )
{
printf( "\nAt Hyderabad" ) ;
printf( "\nGoing back home\n" ) ;
}
chennai( )
{
printf( "\nAt Chennai" ) ;
printf( "\nGoing back home\n" ) ;
}
bengaluru( )
{
printf( "\nAt Bengaluru" ) ;
printf( "\nGoing back home\n" ) ;
}
int main( )
{
printf( "At home\n" ) ;
printf( "\nGoing to Bengaluru" ) ;
bengaluru( ) ;
printf( "\nGoing to Chennai" ) ;
chennai( ) ;
printf( "\nGoing to Hyderabad" ) ;
hyderabad( ) ;
}

The output of the above program is as follows:

At home

Going to Bengaluru
At Bengaluru

Going back home

Going to Chennai
At Chennai
Going back home

Going to Hyderabad
At Hyderabad
Going back home

From this program several conclusions can be drawn:

  • Any C program contains at least one function.
  • If a program contains only one function, it must be the main( ).
  • If a C program contains more than one function, then one (and only one) of these functions must be main( ) because program execution always begins with main().
  • There is no limit on the number of functions that might be present in a C program.
  • Each function in a program is called in the sequence specified by the function calls in main( ).
  • After each function has done its thing, control returns to main( ). When main( )runs out of function calls, the program ends.

As we have noted earlier the program execution always begins with main( ). Except for this fact, all C functions enjoy a state of perfect equality. No precedence and no priorities. A function can call another function and the second function can, in turn, call the third function and so on. To better illustrate this, consider the following example.

#include <stdio.h>
hyderabad( ) 
{
    printf ( "\nI am in Hyderabad" ) ;
}
chennai( ) 
{
    printf ( "\nI am in Chennai" ) ;
    hyderabad( ) ;
    printf ( "\nI am back in Chennai" ) ;
}
bengaluru( )
{
    printf ( "\nI am in Bengaluru" ) ;
    chennai( ) ;
    printf ( "\nI am back in Bengaluru" ) ;
}
int main( ) {
printf ( "I am in main" ) ;
bengaluru( ) ;
printf ( "\nI am finally back in main" ) ;
}

The output:

I am in main
I am in Bengaluru
I am in Chennai
I am in Hyderabad
I am back in Chennai
I am back in Bengaluru
I am finally back in main

Here, main( ) calls other functions, which in turn call still other functions. Trace carefully the way control passes from one function to another. Since the compiler always begins the program execution with main( ), every function in a program must be called directly or indirectly by main( ). In other words, the main( ) function drives other functions

Points to remember so far

a. C program is a collection of one or more functions.
b. A function gets called when the function name is followed by a semicolon. For example,

bengaluru( ) 
{
 chennai( ) ;
}

c. A function is defined when the function name is followed by a pair of braces in which one or more statements may be present. For example,

void bengaluru( )
{
   Statement 1 ;
   Statement 2 ;
   Statement 3 ;
}

d. Any function can be called from any other function. Even main( ) can be called from other functions. For example,

#include <stdio.h>
message( )
{
   printf ( "\nMessage" ) ;
   main( ) ;
}
int main( )
{
   message( ) ;
}

Note: This executes without an error but goes into an infinite loop by both the functions calling each other.
e. A function can be called any number of times. For example,

#include <stdio.h>
foo( ) 
{
    printf ( "\nIn foo" ) ;
}
int main( ) {
foo( ) ;
foo( ) ;
}

f. The order in which the functions get called is the same as the order in which the function calls occur and not in the order how the function is defined.

#include <stdio.h>
foo2( )
{
    printf ( "\nIn foo2" ) ;
}
foo1( ) {
printf ( "\nIn foo1" ) ;
}
int main( ) {
foo1( ) ;
foo2( ) ;
}

Here, even though the function foo2 is defined before function foo1, foo1 is called first as the calling statement in the main( ) function occurs in that order. However, it is advisable to define the functions in the same order in which they are called. This makes the program easier to understand.
g. A function can call itself. Such a process is called ‘recursion’. More on that later.
h. A function cannot be defined in another function. Thus, the following program code throws a compilation error.

#include <stdio.h>
int main( ) 
{
     printf ( "\nI am in main" ) ;
     foo( ) 
   {
       printf ( "\nI am in foo" ) ;
   }
}

There are basically two types of functions:
i. Library functions Ex. printf( ), scanf( ) etc.
ii. User-defined functions Ex. bengaluru( ), chennai( ) etc.
As the name suggests, library functions are commonly required functions grouped and stored in what is called a Library. This library of functions is present on the disk and is written by compiler authors. Almost always a compiler comes with a library of standard functions. The procedure of calling both types of functions is the same.

Advantages of using functions:

  • The use of functions enhances the readability of a program. A big code is always difficult to read. Breaking the code into smaller Functions keeps the program organized, easy to understand and makes it reusable.
  • The C compiler follows top-to-down execution, so the control flow can be easily managed in the case of functions. The control will always come back to the main() function.
  • It reduces the complexity of a program and gives it a modular structure.
  • In case we need to test only a particular part of the program we will have to run the whole program and figure out the errors which can be quite a complex process. Another advantage here is that functions can be individually tested which is more convenient than the above-mentioned process.
  • A function can be used to create our header file or a function can be called n number of times in the same file which can be used in any number of programs i.e. the reusability. This also helps in error isolation during the debug process.
  • Functions help in dividing a complex problem into simpler ones.

Passing values between functions:

  • Communication between the ‘calling’ and the ‘called’ functions is necessary during various scenarios.
  • The mechanism used to convey information to the function is the ‘argument’.
  • You have unknowingly used the arguments in the printf( ) and scanf( ) functions; the format string and the list of variables used inside the parentheses in these functions are arguments.
  • In the following program, in main( ) we receive the values of a, b and c through the keyboard and then output the sum of a, b and c. The calculation of sum is done in function calculate_sum( ). So, we must pass on the values of a, b, c to calculate_sum( ), and once calculate_sum( ) calculates the sum we must return it from calculate_sum( ) back to main( ).
#include <stdio.h>
int calculate_sum ( x, y, z )
int x, y, z ;
{
    int d ;
    d = x + y + z ;
    return ( d ) ;
}
int main( )
{
    int a, b, c, sum ;
    printf ( "\nEnter any three numbers " ) ;
    scanf ( "%d %d %d", &a, &b, &c ) ;
    sum = calculate_sum ( a, b, c ) ;
    printf ( "\nSum = %d", sum ) ;
}

output

Enter any three numbers 1 2 3
Sum = 6

Points to note:

  • The values a, b, c are passed from main( ) to caculate_sum( ) by making a call to the function calculate_sum( ) and mentioning a, b and c in the parentheses:
sum = calculate_sum ( a, b, c ) ;
  • In the calculate_sum( ) function these values get collected in three variables x, y and z:
calculate_sum ( x, y, z )
int x, y, z ;
  • The variables a, b and c are called ‘actual arguments’, whereas the variables x, y and z are called ‘formal arguments’ or ‘parameters’.
  • Any number of arguments can be passed to a function being called. The order, type and the number of the actual and formal arguments must always be the same.
  • Instead of using different variable names x, y and z, we could have used the same variable names a, b and c. But the compiler would still treat them as different variables since they are in different functions.
  • There are two methods of declaring formal arguments. The one that we have used in our program is known as the Kernighan and Ritchie (or just K & R) method.
calculate_sum ( x, y, z )
int x, y, z ;
  • Another method is the ANSI method which is more commonly used:
calculate_sum ( int x, int y, int z )
  • In the above program, we want to return the sum of x, y and z. Therefore, it is necessary to use the return statement. The return statement serves two purposes:
    • On executing the return statement it immediately transfers the control back to the calling function.
    • It returns the value next to return, to the calling program. In the above program, the value of the sum of three numbers is returned.
  • There is no restriction on the number of return statements in a function. Also, the return statement need not always be present at the end of the called function. The following program illustrates these facts.
foo( ) 
{
char ch ;
printf ( "\nEnter any alphabet " ) ;
scanf ( "%c", &ch ) ;
if ( ch >= 65 && ch <= 90 )
    return ( ch ) ;
else
    return ( ch + 32 ) ;
}
  • In this function, different return statements will be executed depending on the evaluation of if-else.
  • Whenever the control returns from a function some value is returned. If a meaningful value is returned then it should be accepted in the calling program by equating the called function to some variable. For example,
sum = calculate_sum ( a, b, c ) ;
  • All the following are valid return statements given that the return type of the functions they are in, justify the data-type of values being returned by return statements.
return ( a ) ; // If the return type of the function is the
same as that of the data type of ‘a’
return ( 23 ) ; // If the return type of the function is int
return ( 12.34 ) ; // If the return type of the function is
float or double
return 89 ; // If the return type of the function is int
return ; // If the return type of the function is void
  • In the last statement, a garbage value is returned to the calling function since we are not returning any specific value. Note that in this case the parentheses after return are dropped.
  • If we want that a called function should not return any value, in that case, we must mention so by using the keyword void as shown below.
void display( ) 
{
printf ( "\nHeads I win..." ) ;
printf ( "\nTails you lose" ) ;
}
  • A function can return only one value at a time. Thus, the following statements are invalid.
return ( a, b ) ;
return ( x, 12 ) ;
  • But the following examples are valid:
return ( a ) ;
return ( x ) ;
  • If the value of a formal argument is changed in the called function, the corresponding change does not take place in the calling function. For example,
#include <stdio.h>
fun ( int b ) {
    b = 60 ;
    printf ( "\n%d", b ) ;
}
int main( )
 {
    int a = 30 ;
    fun ( a ) ;
    printf ( "\n%d", a ) ;
}

Output:

60
30
  • Even if the value of b is changed in fun( ), the value of ‘a’ in main( ) remains unchanged. This means that when values are passed to a called function the values present in actual arguments are not physically moved to the formal arguments; just a photocopy of values of the actual argument is made into formal arguments.

Scope Rule of Functions

Consider the following program

display ( int j ) 
{
   int k = 35 ;
   printf ( "\n%d", j ) ;
   printf ( "\n%d", k ) ;
}
int main( )
{
   int i = 20 ;
   display ( i ) ;
}
  • Note that the main function is sending the value 20 in variable ‘i’ to the function display( ).
  • This program begs a vital question. Is it necessary to send the value of ‘i’ to display( )? Is it not possible for the display( ) function to directly access it without main( ) having to pass the value?
  • The answer to the above questions is No. Because by default the scope of a variable is local to the function in which it is defined. The presence of i is known only to the function main( ) and not to any other function.
  • Similarly, the variable k is local to the function display( ) and hence it is not available to main( ). That is why to make the value of ‘i’ available to display( ) we have to explicitly pass it to display( ). This is done by calling functions. A function can be called in 2 ways.
    ○ Call by value (Which we are seeing in this section)
    ○ Call by reference (Which we will see in a short while)
  • Likewise, if we want k to be available to main( ) we will have to return it to main( ) using the return statement. In general, we can say that the scope of a variable is local to the function, more specifically, the block in which it is defined.

Calling convention

  • Calling convention indicates the order in which arguments are passed to a function when a function call is encountered. There are two possibilities here:
    • Arguments might be passed from left to right.
    • Arguments might be passed from right to left.

C language follows the second order. Consider the following function call:

fun (a, b, c, d ) ;

In this call, it doesn’t matter whether the arguments are passed from left to right or from right to left. However, in some function calls, the order of passing arguments becomes an important consideration. For example:

int a = 1 ;
printf ( "%d %d %d", a, ++a, a++ ) ;

It appears that this printf( ) would output 1 2 3. This however is not the
case. Surprisingly, it outputs 3 3 1. This is because C’s calling convention is from right to left.

Call by Value and Call by Reference

Whenever we have called a function with arguments, we have always passed the ‘values’ of variables to the called function. Such function calls are called ‘call by value’. All the examples we saw till now that pass values to functions were called by value. For example:

f = factr ( a ) ;

Here, one can see that the ‘value’ of ‘a’ is being passed to function factr().
Hence, call by value. One can pass the address of the variable to the function. This is called ‘call by reference’. Note that this feature of C functions needs at least an elementary knowledge of a concept called ‘pointers’.
In call by reference, the addresses of actual arguments in the calling function are copied into formal arguments of the called function. This means that by using these addresses we would have access to the actual arguments and hence we would be able to manipulate them. The following program illustrates this fact.

#include <stdio.h>
void swap( int *x, int *y )
{
     int t ;
     t = *x ;
    *x = *y ;
    *y = t ;
}
int main( )
{
int a = 10, b = 20 ;
swap ( &a, &b ) ;
printf ( "\na = %d b = %d", a, b ) ;
}

Output:

a = 20 b = 10

Note that this program swaps the values of a and b using their addresses stored in x and y. Using a call by reference intelligently we can make a function return more than one value at a time, which is not possible ordinarily. This is shown in the program given below.

#include <stdio.h>
void area_perimeter ( float r, float *a, float *p )
{
*a = 3.14 * r * r ;
*p = 2 * 3.14 * r ;
}
int main( ) 
{
     float area, perimeter, radius ;
     printf ( "\nEnter radius of a circle " ) ;
     scanf ( "%f", &radius ) ;
     area_perimeter ( radius, &area, &perimeter ) ;
     printf ( "Area = %f", area ) ;
     printf ( "\nPerimeter = %f", perimeter ) ;
}

Output

Enter radius of a circle 5
Area = 78.500000
Perimeter = 31.400000

Here, we are passing the value of radius but addresses of area and perimeter. And since we are passing the addresses, any change that we make in values stored at addresses contained in the variables a and p would make the change effective in main( ). That is why when the control returns from the function area_perimeter( ) we can output the values of area and perimeter.
Thus, we have been able to indirectly return two values from a called function, and hence, have overcome the limitation of the return statement, which can return only one value from a function at a time.

Library functions

  • Note that pow(), printf(), scanf(), sqrt() etc are all library functions that are already defined by compiler authors and are ready to use as they come shipped with the compiler.
  • But one cannot use these functions without “including the header file” associated with the functions.
  • Header files are a special type of file that only contain the function prototypes, i.e., the function name, return type and the order and data type of the parameters of the functions.
  • Once the header file is included, it helps the compiler to evaluate the function calls you do in your program to find if there is any mismatch in the way you are calling and the way it has to be called. If there is a mismatch, the compiler throws a compile-time error namely ‘undefined reference’ which means that the function call you are making is referring to no function definition.
  • So it is not just essential to include the header files corresponding to the functions you are going to use in the program but it is equally important to call the functions with the proper name, arguments, the data type, and order of the arguments.

Exercises

  1. Write a function to calculate the factorial value of any integer entered through the keyboard. The function is to take the integer as the parameter and return the factorial of the received number back. Read the user input and print the factorial in the main function.
  2. Write a function power ( a, b ), to calculate the value of a raised to b. Read a and b using scanf( ) in main( ) and print the power value returned from power( ) function in main( ) function.
  3. Write a function to take a year as an input parameter and return 1 if the year is a leap year and 0 otherwise.
  4. Write a function to take a positive integer as an input parameter and return 1 if the integer is palindrome and 0 otherwise.
  5. Write a function to take a positive integer as an input parameter and print the prime factors of the input integer. Let the return type of the function be void. a. Prime factors of the 24 are 2, 2, 2 and 3, whereas prime factors of 35 are
    5 and 7
  6. Write a function that receives a float and an int from main( ), finds the product of these two and returns the product which is printed through main( ).
  7. Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. Call this function from main( ) and print the results in main( ).
  8. Write a function that receives marks received by a student in 3 subjects and returns the average and percentage of these marks. Call this function from main() and print the results in main( ).
  9. A 5-digit positive integer is entered through the keyboard, write a function to calculate the sum of digits of the 5-digit number. Call this function from main( ) and print the results in main( ).
  10. Write a function to find the binary equivalent of a given decimal integer as an argument and display it.

Function Declaration and Prototypes

Any C function by default returns an int value. By default (when you do not mention a return type), the return type of a function is assumed to be an integer. If we desire that a function should return a value other than an int, then it is necessary to explicitly mention it. Suppose we want to find out the square of a number using a function. This is what this simple program would look like:

#include <stdio.h>
#include <math.h>
square ( float x ) 
{
    float y ;
    y = x * x ;
    return ( y ) ;
}
int main( ) 
{
    float a, b ;
    printf ( "Enter any number " ) ;
    scanf ( "%f", &a ) ;
    b = square ( a ) ;
    printf ( "Square of %f is %f", a, b ) ;
}

And here are three sample runs of this program…

Enter any number 3
Square of 3 is 9.000000
Enter any number 1.5
Square of 1.5 is 2.000000
Enter any number 2.5
Square of 2.5 is 6.000000

The first of these answers is correct. But a square of 1.5 is not 2. Neither is 6 a square of 2.5. This happened because any C function, by default, always returns an integer value. Therefore, even though the function square( ) calculates the square of 1.5 as 2.25, the problem crops up when this 2.25 is to be returned to main( ). square( ) is not capable of returning a float value. So it typecasts 2.25 to integer i.e.2 and then it
returns 2. The value 2 is stored in b which is a floating-point variable. This will cause the compiler to typecast an integer value to a floating-point value i.e. 2.000000. The following program segment illustrates how to make square( ) capable of returning a float value.

#include <stdio.h>
#include <math.h>
int main( )
{
    float square ( float ) ;
    float a, b ;
    printf ( "Enter any number " ) ;
    scanf ( "%f", &a ) ;
    b = square ( a ) ;
    printf ( "Square of %f is %f", a, b ) ;
}
float square ( float x ) 
{
    float y ;
    y = x * x ;
    return ( y ) ;
}

output

Enter any number 1.5

Square of 1.5 is 2.250000
Enter any number 2.5
Square of 2.5 is 6.250000

Now the expected answers i.e. 2.25 and 6.25 are obtained. Note that the function square( ) must be declared in main( ) as

float square ( float ) 

This statement is often called the prototype declaration of the square( ) function. This means that square( ) is a function that receives a float and returns ‘a’ float. We have done the prototype declaration in main( ) because we have called it from main( ). There is a possibility that we may call square( ) from several other functions other than main( ). In such a case we would make only one declaration outside all the functions at the beginning of the program.
In some programming situations, we want that a called function that should not return any value. This is made possible by using the keyword void. This is illustrated in the following program.

#include <stdio.h>
#include <math.h>
int main( ) 
{
   void foo( ) ;
   foo( ) ;
}
void foo( )
{
   printf ( "\nIn foo" ) ;
}

Here, the foo( ) function has been defined to return void; which means it would return nothing. Therefore, it would just flash the message and return the control back to the main( ) function.
One can avoid writing function prototypes altogether. Just place the function definition anywhere before the function is called for the first time and the compiler should not throw any warning or errors. The same program as above can be rewritten as follows:

#include <stdio.h>
#include <math.h>

void foo( ) 
{
  printf ( "\nIn foo" ) ;
}
int main( ) 
{
  foo( ) ;
}

This produces the same output as the previous one. It is always advised to declare the function prototypes soon after the header files in the order they are called and then define the main( ) after which the functions can be defined in the order they have been declared.

Variadic functions

Variadic functions are functions (e.g. printf) that take a variable number of arguments. The declaration of a variadic function uses an ellipsis as the last parameter, e.g.

int printf(const char* format, ...);

Accessing the variadic arguments from the function body uses the following library facilities from stdarg.h:

  1. va_list: A data type that holds the information needed by va_start, va_arg, va_end, and va_copy.
  2. va_start: Enables access to variadic function arguments. Should be called first. This takes two parameters: identifier of type va_list and number of arguments.
  3. va_arg: Accesses the next variadic function arguments. Takes two parameters: identifier of type va_list and data type of the value currently being traversed. This returns the value being traversed.
  4. va_copy: Makes a copy of the variadic function arguments.
  5. va_end: Ends traversal of the variadic function arguments. Takes one parameter: identifier of type va_list which was used in va_start.

The following example illustrates a variadic function:

#include <stdio.h>
#include <stdarg.h>
// The first argument is the total number of arguments being passed.
// This is done for the ease to know when to stop traversing a list
of arguments.
double average(int num,...)
{
    va_list valist;
    double sum = 0.0;
    int i;
    /* initialize valist for num number of arguments */
    va_start(valist, num);
    /* access all the arguments assigned to valist */
    for (i = 0; i < num; i++) {
    sum += va_arg(valist, int);
}
    /* clean memory reserved for valist */
    va_end(valist);
    return sum/num;
}
int main() 
{
    printf("Average of 2, 3, 4, 5 = %f\n", average(4, 2,3,4,5));
    printf("Average of 5, 10, 15 = %f\n", average(3, 5,10,15));
    return 0;
}

Recursion

  • In its simplest sense, recursion in a programming language is a function calling itself. That is, the caller function and the called function are the same.
  • A typical recursive function consists of an exit condition that, upon being true, breaks the process of the function calling itself. And an optional logic of operation and then a statement to call itself.
  • To understand recursion better, consider the following program to calculate the factorial of a given number. Note that this approach doesn’t make use of recursion.
#include <stdio.h>
int factorial ( int x )
{
    int f = 1, i ;
    for ( i = x ; i >= 1 ; i-- )
    f = f * i ;
    return ( f ) ;
}
int main( )
{
    int a, fact ;
    printf ( "\nEnter any number " ) ;
    scanf ( "%d", &a ) ;
    fact = factorial ( a ) ;
    printf ( "Factorial value = %d", fact ) ;
}

Output

Enter any number 3
Factorial value = 6
  • Now, the following is the recursive version of the function to calculate the factorial value.
#include <stdio.h>
int rec ( int x )
{
    int f ;
    if ( x == 1 )
       return ( 1 ) ; // Exit condition
    else
       f = x * rec ( x - 1 ) ;
    return ( f ) ;
}
int main( )
{
     int a, fact ;
     printf ( "\nEnter any number " ) ;
     scanf ( "%d", &a ) ;
     fact = rec ( a ) ;
     printf ( "Factorial value = %d", fact ) ;
}

And here is the output for four runs of the program

Enter any number 1
Factorial value = 1
Enter any number 2
Factorial value = 2
Enter any number 3
Factorial value = 6
Enter any number 5
Factorial value = 120
  • In the first run number is 1, the condition if ( x == 1 ) is satisfied and hence 1 (which indeed is the value of 1 factorial) is returned through the return statement.
  • When the number is 2, the ( x == 1 ) test fails, so we reach the statement
f = x * rec ( x - 1 ) ;
  • And here is where we meet recursion. Since the current value of x is 2, it is the same as saying that we must calculate the value (2 * rec ( 1 )). Now the control goes into the rec( ) function again with 1 as an argument. The function returns 1 and hence value (2 * rec( 1 )) reduces to (2 * 1) and the value 2 is returned to main ( ).
  • Now perhaps you can see what would happen if the value of a is 3, 4, 5 and so on.
    ● For the value of a = 5, we might say what happens is,
    ○ rec ( 5 ) returns ( 5 times rec ( 4 ),
    ■ which returns ( 4 times rec ( 3 ),
    ● which returns ( 3 times rec ( 2 ),
    ○ which returns ( 2 times rec ( 1 ),
    ■ which returns ( 1 )
    ○ )
    ● )
    ■ )
    ○ )

Exercises

  1. A 5-digit positive integer is entered through the keyboard, write a function to calculate the sum of digits of the 5-digit number using recursion
  2. A positive integer is entered through the keyboard and write a program that prints the prime factors of the number recursively.
  3. Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence.
  4. A positive integer is entered through the keyboard, write a function to find the binary equivalent of this number using recursion.
  5. Write a recursive function to obtain the running sum of the first 25 natural numbers.
  6. Given three variables x, y, z write a function to circularly shift their values to right. In other words if x = 5, y = 8, z = 10 after circular shift y = 5, z = 8, x =10 after
    circular shift y = 5, z = 8 and x = 10. Call the function with variables a, b, c to circularly shift values. Hint: Use call by reference function calls.

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page