0
What's the output of this code AND WHY? EXPLAIN PLEASE
void func (int &x) { int x= 5; } int main () { int x =2 func (x) cout x; }
1 Answer
+ 5
Output is 5 because function's "func" argument is of reference type (int &x). So that means it will be working with the exactly same variable x you declared in main function. So it sets x = 5 and x stays that way