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

Which one between if-else and switch is more efficient?

0 Answers  


Why c++ is so important?

0 Answers  


what you know about c++?

0 Answers   IBS,


What is an iterator class in c++?

0 Answers  


diff between pointer and reference in c++?

1 Answers  






What is difference between c++ and c ++ 14?

0 Answers  


Is c++ a software?

0 Answers  


What is a virtual destructor?

2 Answers  


What is an html tag?

0 Answers  


What is c++ and its features?

0 Answers  


What are static variables?

0 Answers  


Declare a class vehicle and make it an abstract data type.

0 Answers  


Categories