

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Assignment operator, Return Type, Parameter, Return type is String, Self Assignment problem, Modify the operator, Primitive types, Other Binary operators, Data vulnerability are points you can learn in this Object Oriented Programming lecture.
Typology: Exercises
1 / 25
This page cannot be seen from the preview
Don't miss anything!
int main(){
String str1(“ABC");
String str2(“DE”), str3(“FG”);
str1 = str2; // Valid…
str1 = str2 = str3; // Error…
return 0;
}
str1.operator=(str2.operator=
(str3))
String & String :: operator = (const String & rhs){
size = rhs.size;
delete [] bufferPtr;
if(rhs.size != 0){
bufferPtr = new char[rhs.size+1];
strcpy(bufferPtr,rhs.bufferPtr);
}
else bufferPtr = NULL;
return *this;
}
void main(){
String str1(“AB"); String str2(“CD”), str3(“EF”); str1 = str2; str1 = str2 = str3; // Now valid…
}
int main(){
String str1("Fakhir");
// Self Assignment problem…
str1 = str1;
return 0;
}
… // size = rhs.size; // delete [] bufferPtr; …
str
Fakhir
int main(){
String str1("Fakhir");
str1 = str1;
return 0;
}
as follows:
But we can do the following with
primitive types:
int main(){
int a, b, c;
(a = b) = c;
return 0;
}