49.swap_value_uisng_pointer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace swap_value_uisng_pointer
{
class Program
{
unsafe public static void swap(int* x, int* y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
static unsafe void Main(string[] args)
{
int a = 33;
int b = 22;
Console.WriteLine("Before Swamp() : a={0}, b={1}", a, b);
swap(&a, &b);
Console.WriteLine("After Swap() : a={0}, b={1}", a, b);
Console.Read();
}
}
}
OUTPUT:
Before Swamp() : a=33, b=22
After Swap() : a=22, b=33
Comments
Post a Comment