In inline functions, the compiler is suggested to copy a piece of code at compile time into the caller program.
#include<iostream>
inline void swap(int *a, int *b){
a=a^b;
b=a^b;
a=a^b;
}
int main(){
int a=2,b=3;
swap(a,b);
std::cout<<a<<b;
return 0;
}
Here, the swap function is call by value.
So, suppose that the above code is inlined by the compiler, then will the actual variable a
and b
will be passed so that it works perfectly or the part that has an inline function has some other scope?
Because, if it is inlined, the code is directly copied into main
here, and since no parameter passing will take place, the code have the access to a
and b
.
ps:The question has been edited because I was not able to precisely put in words my doubt so it has so may downvotes.