- 3
What is difference between 1 and 2 and why I am not getting the output in case 2??
1.include <iostream> #include<string> using namespace std; class my { public: void no(string x) { name = x; } string getyes() { return name; } private: string name; }; int main() { my z; z.no("No utput"); cout << z.getyes(); return 0; } 2.#include <iostream> #include<string> using namespace std; class my { public: void no(string x) { x = name; } string getyes() { return name; } private: string name; }; int main() { my z; z.no("No utput"); cout << z.getyes(); return 0; }
4 Antworten
+ 4
In 2 nd one you are assigning value to a local variable , i .e . x
+ 4
Shaik.Shahir do you realise what assigning a value means ? And how value is assigned to left side operand instead of right side one .
You never assigned value to name in 2nd case , how can you expect an output ?
+ 1
Hooo!got it
0
But why I am not getting the output in case 2??