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

Why do we use the using declaration?

0 Answers  


Differentiate between C and C++.

0 Answers   Wipro,


What is a sequence in c++?

0 Answers  


can anybody please tell me how to write a program in c++,without using semicolon(;)

6 Answers   NIIT,


Explain what are mutator methods in c++?

0 Answers  






pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count all the paper bills in the number being input.. example: enter a number: 3886 there is/are: 3 ->1000 1 ->500 3 ->100 1 ->50 1 ->20 1 ->10 1 ->5 1 ->1 example2: enter a number: 728 there is/are: 0 ->1000 1 ->500 2 ->100 0 ->50 1 ->20 0 ->10 1 ->5 3 ->1

4 Answers  


Differentiate between a deep copy and a shallow copy?

1 Answers  


Where and why do I have to put the "template" and "typename" keywords?

0 Answers  


Write about the stack unwinding?

0 Answers  


What is std :: endl?

0 Answers  


What is setbase c++?

0 Answers  


What is the difference between C and CPP?

0 Answers   iNautix,


Categories