Using C languages- swapping the values
#include <stdio.h>
// swapping function
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
// printf("Value of :\n c= %d d= %d\n", a, b);
}
int main()
{
int c = 9;
int d = 3;
/////////////////Pointers
int *ptr_c;
int *ptr_d;
ptr_c = &c;
ptr_d = &d;
//////////////
// Deferencing the values stored at pointer by using '*' at start of pointer
printf("--->%d \n", *ptr_c);
// Deferencing the values stored at pointer by using '*' at start of pointer
printf("--->%d \n", *ptr_d);
//////////////////////////
// swapping two values ---CAll by Reference
swap(ptr_c, ptr_d);
printf("Value of :\n c= %d d= %d\n", c, d);
return 0;
}
No comments:
Post a Comment