+ 1
What is the problem in the code?
swap two values using function by reference method , https://code.sololearn.com/csfvq2IfQ2K7/?ref=app
4 Answers
+ 6
Nothing. Just in printf should be *a and *b for printing the values and not the addresses.
+ 4
"but if I print in definition part then I don't have to use pointer a and b"
void swap(int*a,int*b)
{
    int t;
    t=*b;
    *b=*a;
    *a=t;
    printf("after swapping\n%d and %d",a,b); // Output: 2358860 and 2358856 (decimal represemtation of where a and b point to)
    
    printf("after swapping\n%d and %d", *a, *b); // Sample Output: 5 and 2 (for input 2 and 5)
}
So, they still need to get dereferenced through indirection (asterisk) operator.
0
ah I see thks ,but if I print in definition part then I don't have to use pointer a and b
0
yea I see



