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;

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the syntactic rules to be avoid ambiguity in multiple inheritance?

629


Is c++ used anymore?

585


Specify some guidelines that should be followed while overloading operators?

614


What is the role of static keyword for a class member variable?

627


If dog is a friend of boy, is boy a friend of dog?

567






What is a .lib file in c++?

564


What is meant by const_cast?

644


What is a c++ object?

614


What is #include iostream in c++?

587


Differentiate between a constructor and a method in C++.

556


What methods can be overridden in java?

667


Explain the difference between using macro and inline functions?

574


Explain the difference between static and dynamic binding of functions?

547


What is c++ in english?

575


Difference between pointer to constant and constant pointer to a constant. Give example.

637