In computer programming, an assignment is a statement that sets a value to a variable name. The equal symbol (=) designates the operator that is used to do assignment. The right operand’s value is transferred to the left operand in order for this operand to function. The same variable could have a different value at different points in time.
The procedure known as assignment is used to modify the data value kept in a variable. By doing this, the value is transferred into the memory address, replacing anything that was previously there. A binary operator known as an assignment operator helps to alter the variable to its left using the value to its right. To change and assign values to any variables, we make use of the assignment operators.
The assignment operators found in the C language are listed below:
- a fundamental assignment (=)
- Assignment for subtraction (-=)
- (+=) addition assignment
- Assignments for division (/=) and multiplication (*=)
- Assignment modulo (%=)
- Assignment of bits via XOR (=)
- Assignment with bitwise OR (|=)
- assignment AND bitwise (&=)
- Assignment of the bitwise right shift (>>=)
- Assignment of a left shift in bits (=)
A variable may receive different values at various points while a programme is being run. Every assignment replaces the existing value with a fresh one. When a variable’s name is declared, its data type and location in memory are also specified. Declarative statements provide details on named variables and constants used in a programme.
The method of assignment is used to change the value of the data stored in a variable. This replaces whatever that was previously present in the memory address by transferring the value there.
During the course of a program’s execution, a variable could experience a variety of different values. Every assignment swaps out the current value for a new one.
The data type and memory location of a variable are also given when the variable’s name is declared. Declarative statements give information about named variables and constants that are utilised in a programme.
To give a variable a value, assignment operators are employed. A variable serves as the assignment operator’s left side operand, and a value serves as its right-side operand. The variable on the left must have the same data type as the value on the right side in order for the compiler to avoid raising an error.
The example below shows the different assignment operators:
// C program to demonstrate
// working of Assignment operators
#include <stdio.h>
int main()
{
// Assigning value 10 to a
// using “=” operator
int a = 10;
printf(“Value of a is %d\n”, a);
// Assigning value by adding 10 to a
// using “+=” operator
a += 10;
printf(“Value of a is %d\n”, a);
// Assigning value by subtracting 10 from a
// using “-=” operator
a -= 10;
printf(“Value of a is %d\n”, a);
// Assigning value by multiplying 10 to a
// using “*=” operator
a *= 10;
printf(“Value of a is %d\n”, a);
// Assigning value by dividing 10 from a
// using “/=” operator
a /= 10;
printf(“Value of a is %d\n”, a);
return 0;
}
// C++ program to demonstrate
// working of Assignment operators
#include <iostream>
using namespace std;
int main()
{
// Assigning value 10 to a
// using “=” operator
int a = 10;
cout << “Value of a is “<<a<<“\n”;
// Assigning value by adding 10 to a
// using “+=” operator
a += 10;
cout << “Value of a is “<<a<<“\n”;
// Assigning value by subtracting 10 from a
// using “-=” operator
a -= 10;
cout << “Value of a is “<<a<<“\n”;
// Assigning value by multiplying 10 to a
// using “*=” operator
a *= 10;
cout << “Value of a is “<<a<<“\n”;
// Assigning value by dividing 10 from a
// using “/=” operator
a /= 10;
cout << “Value of a is “<<a<<“\n”;
return 0;
}
A value can be assigned to a variable using the basic assignment operator (=). The value that was assigned is the result of the assignment process. To assign a single value to several variables, you can chain the assignment operator.
This kind of operator is used to assign values to any operation’s variables as well as to alter them. Any given assignment operator has a right side that represents a value and a left side that represents a variable. The data type of the value on the right side of the operator must match the data type of the variable on the left side. The compiler raises an error in any other circumstance. Moreover many students find it difficult to get the programming assignment done, so it is advised to get the help from Assignmentxp.com