Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:29:09+00:00 2026-06-01T11:29:09+00:00

I have a question about my C++ homework. I am just confused about *this.

  • 0

I have a question about my C++ homework. I am just confused about *this.

The code below is what I have.

My question is why the condition in the if statement in the = operator is true?

#include <cstring>
class abc {
      char p[9];
      int inc;
   public:
      abc( ) { inc = 8; strcpy(p, "10010101"); }
      ~abc( );
      abc& operator=(const abc &);

};

abc::~abc( ) {

}
abc& abc::operator=(const abc &c) {
   if(this != &c) { //my question is why this condition is true?
      inc = c.inc - 2;
      for(int i=0; i<inc; i++) {
     p[i] = c.p[i] + 2;
      }
   }
   return *this;
}

int main( ) {
   abc x, y;
   x = y;
   return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:29:10+00:00Added an answer on June 1, 2026 at 11:29 am

    because you don’t want to make a copy if you are assigning to yourself, that is the reason for the if condition, *this returns self instance. It is true because you are trying to assign y to x and as they are both different instances you then make a copy of y to x.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not homework, just a question about my code (I'm learning C++). I
I have a question about a string in C++. As per below code, I
It might be for pedantic purposes but not homework. I have below question about
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I have a question about how GC works in Java. Consider the following code:
I'm finishing up some CSE homework and I have a quick question about declaring
This is a homework question from compiler design course. I just need an explanation
I have this homework question: Assume a Database table has 0 records at time
I have question about throw. How will the throw work in the following code?
I have in my homework some question about data structure: I have elements which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.