Loading....
Coupon Accepted Successfully!

 

Assignment Statements

  • Assignment statement is executed with the help of one or more operations.
  • An assignment statement assigns value to a variable.
  • It is expressed with the equal to symbol (=).
  • The left of the assignation operator is known as lvalue which must be a variable.
  • The right of the assignment operator is known as the rvalue, which must be a constant.
  • For example
    • X = 5;
Note: Assignment statements can be changed.

Type Casting

  • Converting an expression of a given type into another type is known as type casting.
  • There are many types of typecasting available.
  • They are implicit and explicit type casting.
    • Implicit type casting: It does not require any operator. They are automatically performed when a value is copied to a compatible type.
      • For example

short a=100;

int b=a;

b=a;

  • Explicit type casting: It requires an operator. They imply different interpretation of value, require an explicit conversion.
  • For example

long int a=100;

int b;

b=(int)a;

C++ Short hand

  • Cā€‹ ++ offers special short hand notation.
  • The operator is used with an equal to symbol (=).
  • The syntax is

Variablename1=variable operator expression

  • For example

A+=10; // A= A+ 10

The other operators are in the given table

 

Operator

Definition

Example

*=

Multiply and equal to

a*=b;

a=a*b;

/=

Divide and equal to

a/=b;

a=a/b;

+=

Add and equal to

a+=b;

a=a+b;

-=

subtract and equal to

a-=b;

a=a-b;

%=

Modulus and equal to

a%=b;

a=a%b;





Test Your Skills Now!
Take a Quiz now
Reviewer Name