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 is format for defining a structure?

582


What is the use of c++ programming language in real life?

557


What is the latest c++ version?

603


What is c++ & why it is used?

583


How does a copy constructor differs from an overloaded assignment operator?

549






What are the advantages of prototyping?

559


Can I learn c++ without c?

596


Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---

1641


What is the use of lambda in c++?

569


Give example of a pure virtual function in c++?

581


Why should we use null or zero in a program?

594


Is map sorted c++?

507


Which programming language's unsatisfactory performance led to the discovery of c++?

792


what is scupper?

1888


What is the best free c++ compiler for windows?

581