Close
To suscribe Cquery.h please enter your email below..
After suscribing kindly check your mail box immediately
to complete your suscription.
I don't want any update | Let me download
Cquery.h
Code less C fast..
Download v0.1
Cquery.h is written by a student of SSUET by keeping TURBOC compiler in his mind only.
All the code are copyrighted so please respect other's efforts :) and don't distribute Cquery.h with your name.
Thanks.

Thursday, 3 April 2014

swap_int(address variable 1,address variable 2)

Swap takes addresses of two Integer type variables as arguments and swap value of them.


Syntax:


swap_int(address of variable 1 , address of variable 2);

Examples:


#include<cquery.h>
main()
{
int var1 = 1 , var2 = 3;
swap_int(&var1,&var2); //now var1 = 3 and var2 = 1
printf("var1 = %d , var2 = %d ",var1,var2);
}

Order of arguments doesn't matter as you can swap them as also

#include<cquery.h>
main()
{
int var1 = 1 , var2 = 3;
swap_int(&var2,&var1); //now var1 = 3 and var2 = 1
printf("var1 = %d , var2 = %d ",var1,var2);
}

But remember arguments should be direct address or you can use pointers as
#include<cquery.h>
main()
{
int var1 = 1 , var2 = 3;
int *a,*b;
a = &var1;
b = &var2;
swap_int(a,b); //now var1 = 3 and var2 = 1
printf("var1 = %d , var2 = %d ",var1,var2);
}

No comments:

Post a Comment