Predict the output of the below set of programs [1] What is the issue with below program, it prints " After x = 20" where it is expected to print x = 50. Please fix it. #include <iostream> #include <thread> using namespace std; void fun(int x) { cout<<"I am in thread function"<<endl; cout<<"x="<<x<<endl; x = 50; } int main() { int x =20; cout<<"Before x="<<x<<endl; std::thread thobj(fun, std::ref(x)); cout<<"After x="<<x<<endl; thobj.join(); return 0; } void foo() { //... char* p = new char[ 5 ]; p = "Hello"; free( p ); //... } Predict the output of the below program void fun(int &x) { cout<<"I am in thread function"<<endl; cout<<"x="<<x<<endl; ...
Comments
Post a Comment