C Pass Pointers as the Function Arguments

C Pass Pointers as the Function Arguments

Pass pointers as the function arguments in c; Through this tutorial, we will learn how to pass pointers as the function arguments in c.

C Pass Pointers as the Function Arguments

/* Pass Pointers to Functions in C Example  */

#include<stdio.h>
 
void Swap(int *x, int *y)
{
    int Temp;
    Temp = *x;
    *x = *y;
    *y = Temp;
}

int main()
{
    int a, b;
    
    printf ("Please Enter 2 Integer Values :  ");
    scanf("%d %d", &a, &b);
    
    printf("\nBefore Swapping  A = %d and B = %d", a, b);
    
    Swap(&a, &b);
    
    printf(" \nAfter Swapping   A = %d and B = %d \n", a, b);
}

The output of the above c program; is as follows:

Please Enter 2 Integer Values :  1 2
Before Swapping  A = 1 and B = 2 
After Swapping   A = 2 and B = 1 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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