What is the output of:
String a1 = "Hello";
String a2 = "world!";
String* s1 = &a2;
String& s2 = a1;
s1 = &a1;
s2 = a2;
std::cout << *s1 << " " << s2 << std::endl;
Answers were Sorted based on User's Feedback
Answer / ratan
The output is
world! world!
This is becuase s2 is a reference variable of a1 and we are
assigning s2 value if a2 which is world!.
This is chnaging the value at a1 as well.
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / pokala
world! world! is the right anwer.
Do not confuse with other asnwers.
Same is verified.
| Is This Answer Correct ? | 3 Yes | 0 No |
What is a friend function in c++?
Distinguish between new and malloc and delete and free().
Why did you leave your last job?
What are the advantages of using const reference arguments in a function?
What is pointer in c++ with example?
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends
How the compilers arranges the various sections in the executable image?
What are the advantages and disadvantages of using inline and const?
2 Answers Polaris, TCS, Zimmer Biomet,
Differentiate between a deep copy and a shallow copy?
How do you find out if a linked-list has an end?
Comment on c++ standard exceptions?
What is c++ hash?