why & sign is used in copy constructor

Answers were Sorted based on User's Feedback



why & sign is used in copy constructor..

Answer / sandip

To avoid local copy of object reference (&) is used in copy
constructor.
Moreover if the & is ommited then copy constructor goes in
infinite loop.
eg. if class name is Sample.

Copy constructor without &
Sample :: Sample (Sample s)
{
//Code goes here
}

and we create object as follows. ;
Sample s;
Sample s1(s);

In this scenario program will go in infinite loop.

Is This Answer Correct ?    9 Yes 1 No

why & sign is used in copy constructor..

Answer / neha

Here as address of the object is taken into consideration
thats why here & sign is used

Is This Answer Correct ?    7 Yes 3 No

why & sign is used in copy constructor..

Answer / krishnarao panchadi

Sandip, Good answer. It goes into Infinete loop because, as
the a local copy of the object is created, it will call the
constuctor one more time and another copy will be created
there and so on...

Is This Answer Correct ?    2 Yes 0 No

why & sign is used in copy constructor..

Answer / diraj kumar

it copy con command c baset of lan leval

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More STL Interview Questions

What does stl mean in slang?

0 Answers  


what is an algorithm in terms of STL?

1 Answers   Lucent, Wipro,


what is c++

2 Answers  


how to swap two numbers in a linked list without exchanging the data but only the links?

3 Answers   Wipro,


Is there any error below, its a code to delete all entires from a map #include <map> #include iostream.h int main() { int i =0; map <int, char> TestMap; while(i<3) { TesMap.insert(TestMap::value_type(i,Test)); i++; } typedef map<int, char> :: iterator mapIter =TestMap.begin(); if(mapIter!=TestMap.end()) { TestMap.erase(mapItrer); ++mapIter; } return 0; }

0 Answers  






Waht is inheritance

6 Answers  


totoo po ba ang manga aliens!

0 Answers  


Write a program in C++ to concatenate two strings into third string using pointers

5 Answers  


Question 1)Read the data from one file and remove all the duplicated words and generate an output file containg only using words.Program should also print number of occurance of each words on standard output.(Program must be use STL and iostream object). Question 2)Write a program to convert the lower case contents of file to upper case using STL. Question 3)What is the output of this problem. int i=12; int &r =i; r+r/4; int +p =&r; int *p = &r; P+=r; return 1; Answer :a)12 b)17 c) 30 d)24 E)15 Question 4) #include #include #include void main() { char srcstr[30],desstr[30]; int i,len; clrscr(); cout<<"\nenter the string\n"; cin>>srcstr; len=strlen(srcstr); for(i=0;srcstr[i]!='\0';i++) { desstr[--len]=srcstr[i]; } desstr[i]='\0'; cout<<"\nreversed string is\n"; for(i=0;desstr[i]!='\0';i++) { cout< } getch(); } Answer : A) string output b)tuptuo gnirts c) string d)output Question 5) Class Test { static const Tk=LEN; int q; public: foo(intx =LEN):q(x){}; TGet Q() const { return q:} void call test Foo<long :9> foo(10); std::const<< foo.Getq(); Answer: 7,8,9,10,11 question 6) class A { int a; char b; }; class B:public A { char b; int a; }; What is the size? Answer a)5 bytes for class A and 5 bytes class B b)4 bytes for class A and 8 bytes class B. c).... d)....

2 Answers   Bally Technologies,


wap in c++ which accept a integer array and its size as argument and replaces element having even values with its half and element having odd values with twice its value

1 Answers  


Give the output of the following program main() {int ret; ret=fork();ret=fork();ret=fork();ret=fork(); if(!ret) printf("sun"); else printf("solaris");

8 Answers   Sun Microsystems,


how to overload << and >> operator in c++

3 Answers   Wipro,


Categories