Practical-06
Write a program to swap value of two integer number using UDF.
Code
Practical-06.c
#include <stdio.h> //Include the stdio library
// function to swap two integers without pointers
void swap(int a, int b)
{
int temp = a;
a = b;
b = temp;
printf("Swapped values: a = %d, b = %d\n", a, b);
}
// call swap function
void main(){
int a = 10;
int b = 20;
printf("Original values: a = %d, b = %d\n", a, b);
swap(a, b);
}
Output
Original values: a = 10, b = 20
Swapped values: a = 20, b = 10
Explanation
The swap function takes two integer arguments and swaps their values. The function doesn't return anything. The function is called in the main function and the values of a and b are passed to the function. The function swaps the values of a and b and prints the swapped values. The main function prints the original values of a and b before calling the swap function.