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

How a macro differs from a template?

640


Name the operators that cannot be overloaded in C++?

589


What is class and structure in c++?

563


What are disadvantages of pointers?

569


What are the uses of pointers?

584






Show the declaration for a static function pointer.

580


Is swift better than c++?

544


Write a note about the virtual member function?

608


what is data abstraction in C++?

655


What do you mean by function and operator overloading in c++?

613


Why is c++ considered difficult?

651


What is a friend function in c++?

583


What are 2 ways of exporting a function from a dll?

620


What is the difference between new() and malloc()?

621


Can we specify variable field width in a scanf() format string? If possible how?

666