+ 2
What is the problem here?
#include <iostream> using namespace std; void myFunc(int x) { x = 100; } int main() { int var; myFunc(var); cout << var; } The output is 4202046 How??
1 Answer
+ 17
Use
void myFunc(int &x){ //passed by reference
x=100;
}
You can refer Pass by value and pass by reference section in C++ course.