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



What is the output of: String a1 = "Hello"; String a2 = "world!"; String* s..

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

What is the output of: String a1 = "Hello"; String a2 = "world!"; String* s..

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 the output of: String a1 = "Hello"; String a2 = "world!"; String* s..

Answer / dsp

address of a1 hello

Is This Answer Correct ?    2 Yes 2 No

What is the output of: String a1 = "Hello"; String a2 = "world!"; String* s..

Answer / saranya

Hello World

Is This Answer Correct ?    0 Yes 5 No

Post New Answer

More C++ General Interview Questions

Explain the uses oof nested class?

0 Answers  


Can we use pointers in c++?

0 Answers  


What is a pure virtual function? Why is it represented as = 0...how is the internal implementation for the same

3 Answers   CTS,


What will i and j equal after the code below is executed? Explain your answer.

1 Answers  


how to connect with oracle 9i with server in socket program in c/c++

0 Answers   3i Infotech,






In c++, what is the difference between method overloading and method overriding?

0 Answers  


Why do we use classes in c++?

0 Answers  


Difference between pass by value and pass by reference?

0 Answers  


Can you explain the term "resource acquisition is initialization?"

1 Answers   Amazon,


What is the difference between function overloading and operator overloading?

0 Answers  


What are the debugging methods you use when came across a problem?

1 Answers  


write a program that takes two numbers from user that prints the smallest number

2 Answers  


Categories