swap function
call by value
void swap (int c , int d){
int temp=c;
c=d;
d=temp;
}
int main(){
int a=5,b=10;
swap(a,b);
printf(" %d %d ", a,b);
}
call by address
void swap (int *c , int *d){
int temp=*c;
*c=*d;
*d=temp;
}
int main(){
int a=5,b=10;
swap(&a,&b);
printf(" %d %d ", a,b);
}
call by reference (Only C++)
Last updated