+ 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??

7th Sep 2017, 2:26 PM
Sudheer Tripathi
Sudheer Tripathi - avatar
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.
7th Sep 2017, 2:30 PM
Frost
Frost - avatar