What is Compound Assignment Statement and its Programming?

Asked By 120 points N/A Posted on -
qa-featured

Hi

I am a regular user of this informative site and it really helps me out.

I request to all the experts to help me in understanding the concept of Compound Assignment Statement. Please explain definition view as well as its programming.

Waiting for your guideline

Especially programming Guru “MarkJason” I need your help.

SHARE
Best Answer by Sahil
Best Answer
Best Answer
Answered By 0 points N/A #87679

What is Compound Assignment Statement and its Programming?

qa-featured

C++ language provides compound assignment operators that combine assignment operator with arithmetic operators. Compound Assignment operators are used to perform mathematical operations more easily.

 

As we know the word “Compound” that represents the mixture of two or more things.

And Assignment operators are used to perform some assignments between two variables. The addition of any arithmetic operator with the assignment operator is known simply as “Compound Assignment Operator”.

 

The general syntax of Compound Assignment operator is as follows:

Variable op = expression

 

Variable= the variable to assign value

Op = it can be any arithmetic operator

Expression = it can be a constant, variable or arithmetic expression

 

For example N+=10;

It is equivalent to N=N=10;

Both the statements are equivalent and performs the same operation

Answered By 120 points N/A #87680

What is Compound Assignment Statement and its Programming?

qa-featured

Dear Sahil in the way you explain the Compound Assignment operator is very easy. I understand this concept easily. Specially as you said

 

“The addition of any arithmetic operator with the assignment operator is known simply as Compound Assignment Operator”.

Now please, help me to understand its working in programming.

Answered By 0 points N/A #87681

What is Compound Assignment Statement and its Programming?

qa-featured

Nice work Sahil,

JThomis: I am sending you an example code of Compound Assignment Operator. Hope it will help you.

 

#include<iostream.h>

#include<conio.h>

void Main()

{

            int a;

            clrscr(); //used for clearing the screen before output

           

              a=10;

            cout<<”Value of a =  “<<a<<endl;

 

            a+=5;

            cout<<”Value of a+=5  “<<a<<endl;

           

a-=5;

cout<<”Value of a-=5 “<<a<<endl;

 

            a*=2;

            cout<<”Value of a*=2 “<<a<<endl;

 

            a/=2;

            cout<<”Value of a/=2 “<<a<<endl;

 

              a%=2;

            cout<<”Value of a%=2 “<<a<<endl;

           

getch(); //used to pause the screen until to press any key to continue

 

}

This example is having all the code of arithmetic operators with assignment operators. It will help you to understand the working of compound assignment operators. Please run this code in C++ compiler and check the output to understand fully.

Answered By 150 points N/A #87682

What is Compound Assignment Statement and its Programming?

qa-featured

Marvelous Work, Mark Jason. You are hero

Answered By 120 points N/A #87683

What is Compound Assignment Statement and its Programming?

qa-featured

Thank You both for your kind help and time

MarkJason with the help of your example I understand that all arithmetic operators can be used as compound operators with assignment operators. Thank you for your detailed example

Stay Blessed

Answered By 120 points N/A #87684

What is Compound Assignment Statement and its Programming?

qa-featured

MarkJason Please Help in other Programming Problems, i am waiting for them

Login/Register to Answer

Related Questions