Arguments Passing without pointer

When we pass arguments without pointers the changes made by the function would be done to the local variables of the function.

Below is the C program to pass arguments to function without a pointer:

C




// C program to swap two values
//  without passing pointer to 
// swap function.
#include <stdio.h>
  
void swap(int a, int b)
{
  int temp = a;
  a = b;
  b = temp;
}
  
// Driver code
int main() 
{
  int a = 10, b = 20;
  swap(a, b);
  printf("Values after swap function are: %d, %d",
          a, b);
  return 0;
}


Output

Values after swap function are: 10, 20

Passing Pointers to Functions in C

Prerequisites: 

Passing the pointers to the function means the memory location of the variables is passed to the parameters in the function, and then the operations are performed. The function definition accepts these addresses using pointers, addresses are stored using pointers.

Similar Reads

Arguments Passing without pointer

When we pass arguments without pointers the changes made by the function would be done to the local variables of the function....

Arguments Passing with pointers

...

Contact Us