answersLogoWhite

0

Assignment is not a statement, it is an operator. You use the assignment operator in assignment expressions.

int x = 100; // assigns the value 100 to the memory location referred to by x.

int y = x; // assigns the value of x (100) to the memory location referred to by y.

Classes can override and overload the assignment operator to ensure correct assignment behaviour, particularly important when the class includes a member pointer to memory owned by an instance of the class, or to ensure correct typecasting between objects of different types.

class MyClass{

public:

MyClass():m_pNum=new int(){} // default ctor

MyClass(const MyClass):m_pNum=new int(*MyClass.m_pNum){} // copy ctor

~MyClass(){ delete( m_pNum ); } // dtor

public:

MyClass & operator= (int); // typecast assignment

MyClass & operator= (MyClass &); // standard assignment

private:

int * m_pNum; // memory allocated by constructors.

};

// Assignment operator override required to typecast an integer.

MyClass & MyClass::operator= (int num){

*m_pNum = num;

return( *this );

}

// Assignment operator override required to ensure two instances

// of MyClass do not share the same memory.

MyClass & MyClass::operator= (MyClass & myClass){

*m_pNum = *myClass.m_pNum;

return( *this );

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

What is the optional in a variable declaration statement?

Optional is the assignment of the value of course.int number; //Variable Declarationint number=2; //Assignment Declaration


What statement belong in a procedural languages but not in a non procedural language?

Assignment operator


What symbol is used for an assignment statement in a flowchart?

Assignment is usually indicated using Pascal assignment notation (:=). E.g., x := x + 1. This avoids any confusion with the equality operator (=).


Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).


Can a while statement end in a semicolon?

Yes. A while statement ends in a statement...while (expression) statement...and that statement can be a null statement, a single statement, or a block of statements. In the case of the block of statements, there is also a set of braces surrounding them...while (expression);while (expression) statement;while (expression) {statement1;statement2;...statementN;}In the case where the body of the statement is null, there is no body. This is often done while taking advantage of side effects. For instance, to copy a string you could use...char *strcpy (char *pszDestination, char *pszSource) {char *pszTemp = pszDestination;while ((*pszDestination++ = *pszSource++) != '\0');return pszTemp;}...this works because the post-increment (++) operator has higher precedence than the dereference (*) operator, and because the assignment (=) operator has the value of the assignment, which is compared using the not equal (!=) operator against the string terminator null.Note, carefully, the inner parentheses. They are needed because != has higher precedence than =, and you want it the other way around. Also, some compilers will let you eliminate the != '\0' terms and the inner parentheses, but that is not portable, and most compilers will warn you about assignment in a conditional expression.In the case of a single statement you could use...i= -1;while (++i < argc) printf ("%d %s\n", i, argv[i]);...here the while statement also ends in a semicolon.The case of the block of statements is not shown, because it seems to be understood from the context of the question.

Related Questions

Is it okay to not support your thesis statement in a personal essay?

Not if supporting your thesis statement was part of the assignment.


What is a statement in c language programme?

Any experssion including assignment or a function call can be a statement in C


What is the optional in a variable declaration statement?

Optional is the assignment of the value of course.int number; //Variable Declarationint number=2; //Assignment Declaration


What statement belong in a procedural languages but not in a non procedural language?

Assignment operator


What is the correct punctuation of David asked if the Week 4 assignment needed to be uploaded to Waypoint?

Since it is a statement that David asked, just treat it as a statement. "David asked if the Week 4 assignment needed to be uploaded to Waypoint."


How do you write a arithmetic operations in c using compound assignment statement?

a = b = c


What symbol is used for an assignment statement in a flowchart?

Assignment is usually indicated using Pascal assignment notation (:=). E.g., x := x + 1. This avoids any confusion with the equality operator (=).


Which statement best describes that principle underlying the declaration of independence?

if this is for some APLAC assignment, do it yourself.


Is this statement true or false Internal controls are necessary when there is a separation of ownership from management. What is the meaning of this statement?

i have the exact same question in my accounting assignment. somebody help.


How to write to computer memory?

Any assignment statement writes to memory. For example: F := A + 25 * X;


When signing an Assignment of Benefits statement a patient is?

giving permission to the insurance carrier to pay the physician or dentist directly


What sets a variable to a specific value?

Assignment Statement pg 43 Programming Logic and Design by Tony Gaddis