cppreference.com

Assignment operators.

(C++20)
(C++20)
(C++11)
(C++20)
(C++17)
(C++11)
(C++11)
General topics
(C++11)
-
-expression
block


/
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++11)

expression
pointer
specifier

specifier (C++11)
specifier (C++11)
(C++11)

(C++11)
(C++11)
(C++11)
General
(C++11)
(C++26)

(C++11)
(C++11)
-expression
-expression
-expression
(C++11)
(C++11)
(C++17)
(C++20)
    

Assignment operators modify the value of the object.

Operator name  Syntax  Prototype examples (for class T)
Inside class definition Outside class definition
simple assignment Yes T& T::operator =(const T2& b);
addition assignment Yes T& T::operator +=(const T2& b); T& operator +=(T& a, const T2& b);
subtraction assignment Yes T& T::operator -=(const T2& b); T& operator -=(T& a, const T2& b);
multiplication assignment Yes T& T::operator *=(const T2& b); T& operator *=(T& a, const T2& b);
division assignment Yes T& T::operator /=(const T2& b); T& operator /=(T& a, const T2& b);
remainder assignment Yes T& T::operator %=(const T2& b); T& operator %=(T& a, const T2& b);
bitwise AND assignment Yes T& T::operator &=(const T2& b); T& operator &=(T& a, const T2& b);
bitwise OR assignment Yes T& T::operator |=(const T2& b); T& operator |=(T& a, const T2& b);
bitwise XOR assignment Yes T& T::operator ^=(const T2& b); T& operator ^=(T& a, const T2& b);
bitwise left shift assignment Yes T& T::operator <<=(const T2& b); T& operator <<=(T& a, const T2& b);
bitwise right shift assignment Yes T& T::operator >>=(const T2& b); T& operator >>=(T& a, const T2& b);

this, and most also return *this so that the user-defined operators can be used in the same manner as the built-ins. However, in a user-defined operator overload, any type can be used as return type (including void). can be any type including .
Definitions Assignment operator syntax Built-in simple assignment operator Assignment from an expression Assignment from a non-expression initializer clause Built-in compound assignment operator Example Defect reports See also

[ edit ] Definitions

Copy assignment replaces the contents of the object a with a copy of the contents of b ( b is not modified). For class types, this is performed in a special member function, described in copy assignment operator .

replaces the contents of the object a with the contents of b, avoiding copying if possible (b may be modified). For class types, this is performed in a special member function, described in .

(since C++11)

For non-class types, copy and move assignment are indistinguishable and are referred to as direct assignment .

Compound assignment replace the contents of the object a with the result of a binary operation between the previous value of a and the value of b .

[ edit ] Assignment operator syntax

The assignment expressions have the form

target-expr new-value (1)
target-expr op new-value (2)
target-expr - the expression to be assigned to
op - one of *=, /= %=, += -=, <<=, >>=, &=, ^=, |=
new-value - the expression (until C++11) (since C++11) to assign to the target
  • ↑ target-expr must have higher precedence than an assignment expression.
  • ↑ new-value cannot be a comma expression, because its precedence is lower.

If new-value is not an expression, the assignment expression will never match an overloaded compound assignment operator.

(since C++11)

[ edit ] Built-in simple assignment operator

For the built-in simple assignment, the object referred to by target-expr is modified by replacing its value with the result of new-value . target-expr must be a modifiable lvalue.

The result of a built-in simple assignment is an lvalue of the type of target-expr , referring to target-expr . If target-expr is a bit-field , the result is also a bit-field.

[ edit ] Assignment from an expression

If new-value is an expression, it is implicitly converted to the cv-unqualified type of target-expr . When target-expr is a bit-field that cannot represent the value of the expression, the resulting value of the bit-field is implementation-defined.

If target-expr and new-value identify overlapping objects, the behavior is undefined (unless the overlap is exact and the type is the same).

If the type of target-expr is volatile-qualified, the assignment is deprecated, unless the (possibly parenthesized) assignment expression is a or an .

(since C++20)

new-value is only allowed not to be an expression in following situations:

is of a , and new-value is empty or has only one element. In this case, given an invented variable t declared and initialized as T t = new-value , the meaning of x = new-value  is x = t. is of class type. In this case, new-value is passed as the argument to the assignment operator function selected by .   <double> z; z = {1, 2}; // meaning z.operator=({1, 2}) z += {1, 2}; // meaning z.operator+=({1, 2})   int a, b; a = b = {1}; // meaning a = b = 1; a = {1} = b; // syntax error
(since C++11)

In overload resolution against user-defined operators , for every type T , the following function signatures participate in overload resolution:

& operator=(T*&, T*);
volatile & operator=(T*volatile &, T*);

For every enumeration or pointer to member type T , optionally volatile-qualified, the following function signature participates in overload resolution:

operator=(T&, T);

For every pair A1 and A2 , where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signature participates in overload resolution:

operator=(A1&, A2);

[ edit ] Built-in compound assignment operator

The behavior of every built-in compound-assignment expression target-expr   op   =   new-value is exactly the same as the behavior of the expression target-expr   =   target-expr   op   new-value , except that target-expr is evaluated only once.

The requirements on target-expr and new-value of built-in simple assignment operators also apply. Furthermore:

  • For + = and - = , the type of target-expr must be an arithmetic type or a pointer to a (possibly cv-qualified) completely-defined object type .
  • For all other compound assignment operators, the type of target-expr must be an arithmetic type.

In overload resolution against user-defined operators , for every pair A1 and A2 , where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signatures participate in overload resolution:

operator*=(A1&, A2);
operator/=(A1&, A2);
operator+=(A1&, A2);
operator-=(A1&, A2);

For every pair I1 and I2 , where I1 is an integral type (optionally volatile-qualified) and I2 is a promoted integral type, the following function signatures participate in overload resolution:

operator%=(I1&, I2);
operator<<=(I1&, I2);
operator>>=(I1&, I2);
operator&=(I1&, I2);
operator^=(I1&, I2);
operator|=(I1&, I2);

For every optionally cv-qualified object type T , the following function signatures participate in overload resolution:

& operator+=(T*&, );
& operator-=(T*&, );
volatile & operator+=(T*volatile &, );
volatile & operator-=(T*volatile &, );

[ edit ] Example

Possible output:

[ edit ] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
C++11 for assignments to class type objects, the right operand
could be an initializer list only when the assignment
is defined by a user-defined assignment operator
removed user-defined
assignment constraint
C++11 E1 = {E2} was equivalent to E1 = T(E2)
( is the type of ), this introduced a C-style cast
it is equivalent
to E1 = T{E2}
C++20 compound assignment operators for volatile
-qualified types were inconsistently deprecated
none of them
is deprecated
C++11 an assignment from a non-expression initializer clause
to a scalar value would perform direct-list-initialization
performs copy-list-
initialization instead
C++20 bitwise compound assignment operators for volatile types
were deprecated while being useful for some platforms
they are not
deprecated

[ edit ] See also

Operator precedence

Operator overloading

Common operators

a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b
a <=> b

a[...]
*a
&a
a->b
a.b
a->*b
a.*b

function call
a(...)
comma
a, b
conditional
a ? b : c
Special operators

converts one type to another related type
converts within inheritance hierarchies
adds or removes -qualifiers
converts type to unrelated type
converts one type to another by a mix of , , and
creates objects with dynamic storage duration
destructs objects previously created by the new expression and releases obtained memory area
queries the size of a type
queries the size of a (since C++11)
queries the type information of a type
checks if an expression can throw an exception (since C++11)
queries alignment requirements of a type (since C++11)

for Assignment operators
  • Recent changes
  • Offline version
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link
  • Page information
  • In other languages
  • This page was last modified on 25 January 2024, at 23:41.
  • Privacy policy
  • About cppreference.com
  • Disclaimers

Powered by MediaWiki

C++ Tutorial

C++ functions, c++ classes, c++ reference, c++ examples, c++ assignment operators, assignment operators.

Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator ( = ) to assign the value 10 to a variable called x :

The addition assignment operator ( += ) adds a value to a variable:

A list of all assignment operators:

Operator Example Same As Try it
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

CProgramming Tutorial

  • C Programming Tutorial
  • Basics of C
  • C - Overview
  • C - Features
  • C - History
  • C - Environment Setup
  • C - Program Structure
  • C - Hello World
  • C - Compilation Process
  • C - Comments
  • C - Keywords
  • C - Identifiers
  • C - User Input
  • C - Basic Syntax
  • C - Data Types
  • C - Variables
  • C - Integer Promotions
  • C - Type Conversion
  • C - Type Casting
  • C - Booleans
  • Constants and Literals in C
  • C - Constants
  • C - Literals
  • C - Escape sequences
  • C - Format Specifiers
  • Operators in C
  • C - Operators
  • C - Arithmetic Operators
  • C - Relational Operators
  • C - Logical Operators
  • C - Bitwise Operators
  • C - Assignment Operators
  • C - Unary Operators
  • C - Increment and Decrement Operators
  • C - Ternary Operator
  • C - sizeof Operator
  • C - Operator Precedence
  • C - Misc Operators
  • Decision Making in C
  • C - Decision Making
  • C - if statement
  • C - if...else statement
  • C - nested if statements
  • C - switch statement
  • C - nested switch statements
  • C - While loop
  • C - For loop
  • C - Do...while loop
  • C - Nested loop
  • C - Infinite loop
  • C - Break Statement
  • C - Continue Statement
  • C - goto Statement
  • Functions in C
  • C - Functions
  • C - Main Function
  • C - Function call by Value
  • C - Function call by reference
  • C - Nested Functions
  • C - Variadic Functions
  • C - User-Defined Functions
  • C - Callback Function
  • C - Return Statement
  • C - Recursion
  • Scope Rules in C
  • C - Scope Rules
  • C - Static Variables
  • C - Global Variables
  • Arrays in C
  • C - Properties of Array
  • C - Multi-Dimensional Arrays
  • C - Passing Arrays to Function
  • C - Return Array from Function
  • C - Variable Length Arrays
  • Pointers in C
  • C - Pointers
  • C - Pointers and Arrays
  • C - Applications of Pointers
  • C - Pointer Arithmetics
  • C - Array of Pointers
  • C - Pointer to Pointer
  • C - Passing Pointers to Functions
  • C - Return Pointer from Functions
  • C - Function Pointers
  • C - Pointer to an Array
  • C - Pointers to Structures
  • C - Chain of Pointers
  • C - Pointer vs Array
  • C - Character Pointers and Functions
  • C - NULL Pointer
  • C - void Pointer
  • C - Dangling Pointers
  • C - Dereference Pointer
  • C - Near, Far and Huge Pointers
  • C - Initialization of Pointer Arrays
  • C - Pointers vs. Multi-dimensional Arrays
  • Strings in C
  • C - Strings
  • C - Array of Strings
  • C - Special Characters
  • C Structures and Unions
  • C - Structures
  • C - Structures and Functions
  • C - Arrays of Structures
  • C - Self-Referential Structures
  • C - Lookup Tables
  • C - Dot (.) Operator
  • C - Enumeration (or enum)
  • C - Structure Padding and Packing
  • C - Nested Structures
  • C - Anonymous Structure and Union
  • C - Bit Fields
  • C - Typedef
  • File Handling in C
  • C - Input & Output
  • C - File I/O (File Handling)
  • C Preprocessors
  • C - Preprocessors
  • C - Pragmas
  • C - Preprocessor Operators
  • C - Header Files
  • Memory Management in C
  • C - Memory Management
  • C - Memory Address
  • C - Storage Classes
  • Miscellaneous Topics
  • C - Error Handling
  • C - Variable Arguments
  • C - Command Execution
  • C - Math Functions
  • C - Static Keyword
  • C - Random Number Generation
  • C - Command Line Arguments
  • C Programming Resources
  • C - Questions & Answers
  • C - Quick Guide
  • C - Cheat Sheet
  • C - Useful Resources
  • C - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

Assignment Operators in C

In C language, the assignment operator stores a certain value in an already declared variable. A variable in C can be assigned the value in the form of a literal, another variable, or an expression.

The value to be assigned forms the right-hand operand, whereas the variable to be assigned should be the operand to the left of the " = " symbol, which is defined as a simple assignment operator in C.

In addition, C has several augmented assignment operators.

The following table lists the assignment operators supported by the C language −

Operator Description Example
= Simple assignment operator. Assigns values from right side operands to left side operand C = A + B will assign the value of A + B to C
+= Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A
-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A
*= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to C = C * A
/= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to C = C / A
%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A
<<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator. C &= 2 is same as C = C & 2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2
|= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2

Simple Assignment Operator (=)

The = operator is one of the most frequently used operators in C. As per the ANSI C standard, all the variables must be declared in the beginning. Variable declaration after the first processing statement is not allowed.

You can declare a variable to be assigned a value later in the code, or you can initialize it at the time of declaration.

You can use a literal, another variable, or an expression in the assignment statement.

Once a variable of a certain type is declared, it cannot be assigned a value of any other type. In such a case the C compiler reports a type mismatch error.

In C, the expressions that refer to a memory location are called "lvalue" expressions. A lvalue may appear as either the left-hand or right-hand side of an assignment.

On the other hand, the term rvalue refers to a data value that is stored at some address in memory. A rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.

Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side. Take a look at the following valid and invalid statements −

Augmented Assignment Operators

In addition to the = operator, C allows you to combine arithmetic and bitwise operators with the = symbol to form augmented or compound assignment operator. The augmented operators offer a convenient shortcut for combining arithmetic or bitwise operation with assignment.

For example, the expression "a += b" has the same effect of performing "a + b" first and then assigning the result back to the variable "a".

Run the code and check its output −

Similarly, the expression "a <<= b" has the same effect of performing "a << b" first and then assigning the result back to the variable "a".

Here is a C program that demonstrates the use of assignment operators in C −

When you compile and execute the above program, it will produce the following result −

  • Skip to main content
  • Skip to search
  • Skip to select language
  • Sign up for free

Assignment (=)

The assignment ( = ) operator is used to assign a value to a variable or property. The assignment expression itself has a value, which is the assigned value. This allows multiple assignments to be chained in order to assign a single value to multiple variables.

A valid assignment target, including an identifier or a property accessor . It can also be a destructuring assignment pattern .

An expression specifying the value to be assigned to x .

Return value

The value of y .

Thrown in strict mode if assigning to an identifier that is not declared in the scope.

Thrown in strict mode if assigning to a property that is not modifiable .

Description

The assignment operator is completely different from the equals ( = ) sign used as syntactic separators in other locations, which include:

  • Initializers of var , let , and const declarations
  • Default values of destructuring
  • Default parameters
  • Initializers of class fields

All these places accept an assignment expression on the right-hand side of the = , so if you have multiple equals signs chained together:

This is equivalent to:

Which means y must be a pre-existing variable, and x is a newly declared const variable. y is assigned the value 5 , and x is initialized with the value of the y = 5 expression, which is also 5 . If y is not a pre-existing variable, a global variable y is implicitly created in non-strict mode , or a ReferenceError is thrown in strict mode. To declare two variables within the same declaration, use:

Simple assignment and chaining

Value of assignment expressions.

The assignment expression itself evaluates to the value of the right-hand side, so you can log the value and assign to a variable at the same time.

Unqualified identifier assignment

The global object sits at the top of the scope chain. When attempting to resolve a name to a value, the scope chain is searched. This means that properties on the global object are conveniently visible from every scope, without having to qualify the names with globalThis. or window. or global. .

Because the global object has a String property ( Object.hasOwn(globalThis, "String") ), you can use the following code:

So the global object will ultimately be searched for unqualified identifiers. You don't have to type globalThis.String ; you can just type the unqualified String . To make this feature more conceptually consistent, assignment to unqualified identifiers will assume you want to create a property with that name on the global object (with globalThis. omitted), if there is no variable of the same name declared in the scope chain.

In strict mode , assignment to an unqualified identifier in strict mode will result in a ReferenceError , to avoid the accidental creation of properties on the global object.

Note that the implication of the above is that, contrary to popular misinformation, JavaScript does not have implicit or undeclared variables. It just conflates the global object with the global scope and allows omitting the global object qualifier during property creation.

Assignment with destructuring

The left-hand side of can also be an assignment pattern. This allows assigning to multiple variables at once.

For more information, see Destructuring assignment .

Specifications

Specification

Browser compatibility

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

  • Assignment operators in the JS guide
  • Destructuring assignment
  • C++ Language
  • Ascii Codes
  • Boolean Operations
  • Numerical Bases

Introduction

Basics of c++.

  • Structure of a program
  • Variables and types
  • Basic Input/Output

Program structure

  • Statements and flow control
  • Overloads and templates
  • Name visibility

Compound data types

  • Character sequences
  • Dynamic memory
  • Data structures
  • Other data types
  • Classes (I)
  • Classes (II)
  • Special members
  • Friendship and inheritance
  • Polymorphism

Other language features

  • Type conversions
  • Preprocessor directives

Standard library

  • Input/output with files

Assignment operator (=)

std; main () { a, b; a = 10; b = 4; a = b; b = 7; cout << ; cout << a; cout << ; cout << b; }

Arithmetic operators ( +, -, *, /, % )

operatordescription
addition
subtraction
multiplication
division
modulo

Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)

expressionequivalent to...
std; main () { a, b=3; a = b; a+=2; cout << a; }

Increment and decrement (++, --)

Example 1Example 2

Relational and comparison operators ( ==, !=, >, <, >=, <= )

operatordescription
Equal to
Not equal to
Less than
Greater than
Less than or equal to
Greater than or equal to
(5 > 4) (3 != 2) (6 >= 6) (5 < 5)
(a*b >= c) (b+4 > a*c) ((b=2) == a)

Logical operators ( !, &&, || )

!(6 <= 4) ! !
&& OPERATOR (and)
|| OPERATOR (or)
( (5 == 5) || (3 > 6) )
operatorshort-circuit
if the left-hand side expression is , the combined result is (the right-hand side expression is never evaluated).
if the left-hand side expression is , the combined result is (the right-hand side expression is never evaluated).
( (i<10) && (++i<n) ) { }

Conditional ternary operator ( ? )

7==5+2 ? 4 : 3 5>3 ? a : b a>b ? a : b
std; main () { a,b,c; a=2; b=7; c = (a>b) ? a : b; cout << c << ; }

Comma operator ( , )

Bitwise operators ( &, |, ^, ~, <<, >> ).

operatorasm equivalentdescription
Bitwise AND
Bitwise inclusive OR
Bitwise exclusive OR
Unary complement (bit inversion)
Shift bits left
Shift bits right

Explicit type casting operator

i; f = 3.14; i = ( ) f;
(f);
( );

Other operators

Precedence of operators.

x = (5 + 7) % 2;
LevelPrecedence groupOperatorDescriptionGrouping
1Scope scope qualifierLeft-to-right
2Postfix (unary) postfix increment / decrementLeft-to-right
functional forms
subscript
member access
3Prefix (unary) prefix increment / decrementRight-to-left
bitwise NOT / logical NOT
unary prefix
reference / dereference
allocation / deallocation
parameter pack
)C-style type-casting
4Pointer-to-member access pointerLeft-to-right
5Arithmetic: scaling multiply, divide, moduloLeft-to-right
6Arithmetic: addition addition, subtractionLeft-to-right
7Bitwise shift shift left, shift rightLeft-to-right
8Relational comparison operatorsLeft-to-right
9Equality equality / inequalityLeft-to-right
10And bitwise ANDLeft-to-right
11Exclusive or bitwise XORLeft-to-right
12Inclusive or bitwise ORLeft-to-right
13Conjunction logical ANDLeft-to-right
14Disjunction logical ORLeft-to-right
15Assignment-level expressions assignment / compound assignmentRight-to-left
conditional operator
16Sequencing comma separatorLeft-to-right

The Simple Assignment Operator

  • The equals sign, =, is known as the assignment operator in C
  • The purpose of the assignment operator is to take the value from the right hand side of the operator ( the RHS value ), and store it in the variable on the left hand side ( the LHS ).
  • X = Y + 7; - Valid: The sum of Y plus 7 will be stored in the variable X.
  • X - Y = 7; - Invalid: Although this looks like a simple rearrangement of the above, the LHS is no longer a valid storage location.
  • 7 = X - Y; - Invalid: The LHS is now a single entity, but it is a constant whose value cannot be changed.
  • X = X + 7; - Valid: First the original value of X will be added to 7. Then this new total will be stored back into X, replacing the previous value.

Arithmetic Operators, +, -, *, /, %

  • Ex: X = Y + 7;
  • Ex: X = Y - 7;
  • Ex: X = - Y;
  • ( + can also be used as a unary operator, but there is no good reason to do so. )
  • Ex: X = Y * 7;
  • Ex: X = Y / 7;
  • 9 / 10 yields zero, not 0.9 or 1.
  • 17 / 5 yields 3.
  • 9.0 / 10 yields 0.9, because there are two different types involved, and so the "smaller" int of 10 is promoted to a double precision 10.0 before the division takes place.
  • int num = 9.0 / 10; stores 0. The division yields 0.9 as in the above example, but then it is truncated to the integer 0 by the assignment operator that stores the result in the int variable "num".
  • Ex: K = N % 7;
  • 17 % 5 yields 2.
  • 3 % 5 yields 3.
  • Mod only works with integers in C.
  • If N % M is equal to zero, then it means N is evenly divisible by M. ( E.g. if N % 2 is 0, then N is even. )
  • Therefore mod is often used to map a number into a given range.
  • For example, rand( ) % 52 always yields a number in the range 0 to 51 inclusive, suitable for randomly selecting a card from a deck of 52 cards.

Precedence and Associativity

  • Ex: what is the value of the expression 3 + 5 / 2 ?
  • Assignment statements have the lowest precedence of all, so all other operations are performed before the result is assigned.
  • Ex: In the expression 3 * ( 4 + 2 ), the addition is performed first, and then the multiplication.
  • Ex: What is the value of the expression 5 / 3 * 2.0 ?
  • A = B = C = 0;
  • A full table of precedence and associativity is included in any good book on C Programming. There are also many versions of this information on the web.

Abbreviated Assignment Operators

  • E.g. X = X + 7;
  • Because this is so common, there are a number of operators that combine assignment with some other ( binary ) operator.
Operator Example Equivalent
  • Note that in these combined operators, that there is no space between the = and the other character, e.g. no space between the + and the = in +=.
  • X *= 3 + 4;
  • The above is equivalent to X = X * ( 3 + 4 );, not X = X * 3 + 4;

Auto Increment and Auto Decrement

  • Another operation that is very common in programming is to either increase or decrease an integer by exactly 1, e.g. when counting up or counting down.
  • N++; is equivalent to N += 1; which is equivalent to N = N + 1;
  • N--; is equivalent to N -= 1; which is equivalent to N = N - 1;
  • There are actually two versions of the auto increment/decrement operators, depending on whether the operator appears after the operand ( postfix, e.g. N++ ) or before the operand ( prefix, e.g. ++N ).
  • For stand-alone statement that consist of nothing but the auto increment/decrement there is no difference between the two. Common convention is to use the postfix form, but prefix would work equivalently.
  • If N is originally equal to 3, then the statement X = 2 * N++ * 3; will store 18 in X and then increment N to 4.
  • If N is originally equal to 3, then the statement X = 2 * ++N * 3; will increment N to 4 first, and then store 24 in X.
  • DANGER: If a variable is affected by an auto increment / decrement operator, never use that same variable more than once in the same statement. For example, the result of X = N++ * 3 + N; is undefined, because it is undetermined what value will be used for the second instance of N.
  • ( Compare N++ +J to N+ ++J )

IncludeHelp_logo

  • Data Structure
  • Coding Problems
  • C Interview Programs
  • C++ Aptitude
  • Java Aptitude
  • C# Aptitude
  • PHP Aptitude
  • Linux Aptitude
  • DBMS Aptitude
  • Networking Aptitude
  • AI Aptitude
  • MIS Executive
  • Web Technologie MCQs
  • CS Subjects MCQs
  • Databases MCQs
  • Programming MCQs
  • Testing Software MCQs
  • Digital Mktg Subjects MCQs
  • Cloud Computing S/W MCQs
  • Engineering Subjects MCQs
  • Commerce MCQs
  • More MCQs...
  • Machine Learning/AI
  • Operating System
  • Computer Network
  • Software Engineering
  • Discrete Mathematics
  • Digital Electronics
  • Data Mining
  • Embedded Systems
  • Cryptography
  • CS Fundamental
  • More Tutorials...
  • Tech Articles
  • Code Examples
  • Programmer's Calculator
  • XML Sitemap Generator
  • Tools & Generators

IncludeHelp

  • C - Getting Started
  • C - Overview
  • C - Advantages & Disadvantages
  • C - Character Set
  • Gcc Vs. G++
  • Why We should Use C?
  • C - Basic Rules
  • C - Comments
  • C - Variable Naming Conventions
  • C - Variable Initialization
  • C - Constants
  • C - Character Constant
  • C - Octal Literals
  • C - Hexadecimal Literals
  • C - Automatic (auto) Variables
  • Local Vs. Global Variables
  • C - Access Global Variables
  • Is exit() & return Statements are Same?
  • C - Print Float Value
  • C - Print Multiple Lines Using printf()
  • C - Argument Index Specification
  • C - Value Returned by scanf()
  • C - Returned Values of printf() & scanf()
  • What do 'lvalue' & 'rvalue' Mean
  • Automatic (auto) Vs. Static Variables

C Data Types

  • C - Data Types & Operators
  • C - Basic Data Types
  • C - 'unsigned char' For Memory Optimization
  • short Vs. short int Vs. int
  • unsigned int Vs. size_t
  • C - Storage Classes Introduction
  • C - Storage Classes With Examples
  • C- Type Conversion
  • C - Type Qualifiers

C Input/Output

  • C - Read String With Spaces
  • C - Input String of Unknown Length
  • C - Disadvantages of scanf()
  • C - scanf() need '%lf' for doubles, when printf() is okay with just '%f'
  • C - Format Specifier for unsigned short int
  • C - printf() Format Specifier for bool
  • C - printf() Arguments for long
  • C - printf() Specifier for double
  • Is there a printf() converter to print in binary format?
  • C - Nested printf()
  • printf() Vs. puts()
  • printf() Vs. sprintf()
  • %d Vs. %i format Specifiers
  • C - Single Character Input & Output
  • C- Formatted Input & Output
  • C - Octal & Hex Escape Sequences
  • C - Convert Float to String
  • gets() Vs. fgets()
  • C - Input Unsigned Integer Value
  • C - Input Octal Value
  • C - Input Hex Value
  • C - Input Decimal, Octal & Hex in char Variables
  • C - Input With '%i'
  • C - Input Individual Characters
  • C - Skip characters While Reading Integers
  • C - Read Memory Address
  • C - Printing Variable's Address
  • C - printf() Examples & Variations

C Operators

  • C - Operators Precedence & Associativity
  • Operators Vs. Operands
  • C - Unary Operators
  • C - Equality Operators
  • C - Logical AND (&&) Operator
  • C - Logical OR (||) Operator
  • C - Logical NOT (!) Operator
  • C - Modulus on Negative Numbers
  • C - Expression a=b=c (Multiple Assignment) Evaluates
  • C - Expression a==b==c (Multiple Comparison) Evaluates
  • C - Complex Return Statement Using Comma Operator
  • C - Comma Operator
  • C - Bitwise Operators
  • C - Bitwise One's Compliment
  • C - Modulus of Float or Double Numbers

C Conditional Statements

  • C - If Else Statements
  • C - Switch Case
  • C - Switch Statements Features, Disadvantages
  • C - Using Range With Switch

C Control Statements

  • C - 'goto' Statement
  • C - break & continue
  • Print Numbers From 1 to N Using goto
  • C - Looping
  • C - Looping Programs
  • C - Nested Loops
  • C - Entry Controlled Vs. Exit Controlled Loops
  • C - Sentinel Vs. Counter Controlled Loops
  • C - Use for Loop as Infinite Loop
  • C - Strings in C language programming
  • C - string.h Functions
  • C - memcpy() Function
  • C - Write Your Own memcpy()
  • C - memset() Function
  • C - Write Your Own memset()

C Functions

  • C - Library & User-define Functions
  • C - Static Functions
  • C - Scope of Function Parameters
  • C - Recursion
  • C - Recursion Examples
  • More on Arrays
  • C - Properties/Characteristics of Array

C Structure and Unions

  • C Structures
  • C - Initialize a Structure in Accordance
  • C - Size of Structure With No Members
  • C -Pointer to Structure
  • C - Nested Structure Initialization
  • C - Nested Structure With Examples
  • C - Size of Structure
  • C - Copy Complete Structure in Byte Array
  • C - Pointer to Union
  • C - Pointers
  • C - Pointer Rules
  • C - Pointers Declarations
  • C - Pointer Address Operators
  • C - Accessing Variable Using Pointer
  • C - Address of (&) & Dereference (*) Operators
  • C - NULL Pointer
  • C - Pointers as Argument
  • C - Pointer Arithmetic
  • C - Pointer to an Array
  • C - Evaluation of Statement '*ptr++'
  • C - Pointer & Non-pointer Variables Declarations Together
  • C - Pointer to an Array of Integers
  • C - Pointer to Pointer
  • C - void Pointer as Function Argument
  • char s[] Vs. char *s
  • C - Copying Integer Value to Char Buffer & Vice Versa
  • C - Call by Reference Vs. Call by Value
  • C - Typedef Function Pointer

C Preprocessor Directives

  • Recommendation for defining a macro in C language
  • Macro expansion directives (#define, #undef) in C language
  • Complex macro with arguments (function like macro) in C language
  • C language #ifdef, #else, #endif Pre-processor with Example
  • C language #if, #elif, #else, #endif Pre-processor with Example
  • Parameterized Macro - we cannot use space after the Macro Name
  • Stringizing Operator (#) in C
  • Token Pasting Directive Operator (##) in C

C Command-line Arguments

  • C language Command Line Arguments

C File Handlings

  • C - Basics of File Handling
  • C - File Handling Programs
  • C - Graphics Modes
  • C - Using Colors in Text Mode
  • C - More on Graphics Modes
  • C - OUTTEXTXY() & SETTEXTSTYLE() Functions
  • C - Draw Circle & Rectangle
  • C - graphics.h Functions
  • C - More Graphics-related Interesting Functions

C Advance Topics

  • C - Process Identification (pid_t)
  • C - getpid() & getppid()
  • C - Rrules For Writing C/C++ Program
  • C - Tips For Embedded Development
  • C - Optimization Techniques
  • C Vs. Embedded C
  • C- File Management System Calls
  • C/C++ Multithreading
  • C/C++ - Sum of Array Using Multithreading

C Tips and Tricks

  • C - Copy Two Bytes Int. to Byte Buffer
  • C - Is Pre-increment Faster than Post-increment?
  • C - Create Delay Function
  • Why should We use 'f' With Float Literal in C?
  • C - Replacing a Part of String
  • C- Comparing Number of Characters of Two Strings
  • C - Safest Way to Check Value Using ==
  • C- Check EVEN or ODD W/O % Operator
  • C- Use Single Byte to Store 8 Values
  • C- Funny Trick to Use C++ in C
  • C - Trick to Print Maximum Value of an unsigned int
  • C - Print Maximum Value of an unsigned int using One's Compliment (~) Operator in C
  • Why we should use switch instead of if else?
  • How to initialize array elements with hexadecimal values in C?
  • How should we declare/define a pointer variable?

C Important Topics

  • C - Working With Hexadecimal
  • C - Working With octal
  • C - Convert ASCII String (char[]) to BYTE Array
  • C - Convert ASCII String (char[]) to Octal String
  • C - Convert ASCII String (char[]) to Hex String
  • C - Assign Binary Calue in a Variable Directly
  • C - Check Particular Bit is SET or Not
  • C- Set, Clear, & Toggle a Bit
  • C - Value of 'EOF'
  • C - Print printf("Hello world."); Using printf()
  • C - Print Text in New Line w/O Using '\n'
  • C - Return 0 From int main()
  • 'Super Loop' Architecture for Embedded C
  • C - Executing System Commands
  • C - Infix To Postfix Conversion Using Stack
  • C - Evaluation of Postfix Expressions Using Stack
  • C - Polynomial Addition Using Structure
  • C - conio.h Functions
  • SQLite with C language
  • C - SQL Table Creation, Insertion
  • C - Aptitude Questions
  • C - Interview Questions
  • C - Find Output Programs

Home » C programming

What is the difference between = (Assignment) and == (Equal to) operators in C?

Difference between assignment (=) vs equal to (==) operators in c.

Many times this question arises what is the difference between = and == operators in C programming language? Here we are going to tell you exactly what the differences between these two operators are.

Assignment Operator (=)

= is an Assignment Operator in C, C++ and other programming languages, It is Binary Operator which operates on two operands.

= assigns the value of right side expression’s or variable’s value to the left side variable.

Let's understand by example:

Here, When first expression evaluates value of (a+b) will be assigned into x and in second expression y=x; value of variable x will be assigned into y .

Equal To Operator (==)

== is an Equal To Operator in C and C++ only, It is Binary Operator which operates on two operands.

== compares value of left and side expressions, return 1 if they are equal other will it will return 0.

When expression x==y evaluates, it will return 1 (it means condition is TRUE ) and "TRUE" will print.

So it's cleared now, , both are not same , = is an Assignment Operator it is used to assign the value of variable or expression, while == is an Equal to Operator and it is a relation operator used for comparison (to compare value of both left and right side operands).

Comments and Discussions!

Load comments ↻

  • Marketing MCQs
  • Blockchain MCQs
  • Artificial Intelligence MCQs
  • Data Analytics & Visualization MCQs
  • Python MCQs
  • C++ Programs
  • Python Programs
  • Java Programs
  • D.S. Programs
  • Golang Programs
  • C# Programs
  • JavaScript Examples
  • jQuery Examples
  • CSS Examples
  • C++ Tutorial
  • Python Tutorial
  • ML/AI Tutorial
  • MIS Tutorial
  • Software Engineering Tutorial
  • Scala Tutorial
  • Privacy policy
  • Certificates
  • Content Writers of the Month

Copyright © 2024 www.includehelp.com. All rights reserved.

What's the Difference Between the Assignment (`=`) and Equality (`==`, `===`) Operators?

assignment operators equal

.css-13lojzj{position:absolute;padding-right:0.25rem;margin-left:-1.25rem;left:0;height:100%;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:none;} .css-b94zdx{width:1rem;height:1rem;} The Problem .css-1s1dm52{margin-left:1rem;}.css-1s1dm52.btn-small{font-size:0.8125rem;font-weight:500;height:auto;line-height:0.75rem;padding:0.5rem 0.75rem;} .css-vgbcnb{margin-left:1rem;}.css-vgbcnb.snackbar{height:auto;padding:0.5rem 0.75rem;}.css-vgbcnb.btn-small{font-size:0.8125rem;font-weight:500;height:auto;line-height:0.75rem;padding:0.5rem 0.75rem;} .css-16p7d4d{margin-left:1rem;}.css-16p7d4d.snackbar{height:auto;padding:0.5rem 0.75rem;}.css-16p7d4d.btn-small{font-size:0.8125rem;font-weight:500;height:auto;line-height:0.75rem;padding:0.5rem 0.75rem;} Jump To Solution

People who are new to programming often find it difficult to understand the difference between = , == , and === .

In mathematics we only use = , so what do the other two mean?

The Solution

The = is an assignment operator, while == and === are called equality operators.

Assignment Operator ( = )

In mathematics and algebra, = is an equal to operator. In programming = is an assignment operator , which means that it assigns a value to a variable.

For example, the following code will store a value of 5 in the variable x :

We can combine the declaration and assignment in one line:

It may look like the assignment operator works the same way as algebra’s equal to operator, but that’s not the case.

For example, the following doesn’t make any sense in algebra:

But it is acceptable in JavaScript (and other programming languages). JavaScript will take the expression on the right-hand side of the operator x + 4 and store this value in x again.

Equality Operator ( == )

In JavaScript, the operator that compares two values is written like this: == . It is called an equality operator . The equality operator is one of the many comparison operators in JavaScript that are used in logical and conditional statements.

The equality operator returns true or false based on whether the operands (the values being compared) are equal.

For example, the following code will return false :

Interestingly, if we compare an integer 5 and a string "5" it returns true .

That is because in most cases, if the two operands are not of the same type, JavaScript attempts to convert them to an appropriate type for comparison. This behavior generally results in comparing the operands numerically.

Strict Equality Operator ( === )

Like the equality operator above, the strict equality operator compares the two values. But unlike the equality operator, the strict equality operator compares both the content and the type of the operands.

So using the strict equality operator, 5 and "5" are not equal.

It is better to use the strict equality operator to prevent type conversions, which may result in unexpected bugs. But if you’re certain the types on both sides will be the same, there is no problem with using the shorter operator.

  • Resources JavaScript Frontend Error Monitoring 101

Syntax.fm logo

Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

A peek at your privacy

Here’s a quick look at how Sentry handles your personal information (PII).

Who we collect PII from

We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.

What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.

PII we may collect about you

  • PII provided by you and related to your
  • Account, profile, and login
  • Requests and inquiries
  • PII collected from your device and usage
  • PII collected from third parties (e.g., social media)

How we use your PII

  • To operate our site and service
  • To protect and improve our site and service
  • To provide customer care and support
  • To communicate with you
  • For other purposes (that we inform you of at collection)

Third parties who receive your PII

We may disclose your PII to the following type of recipients:

  • Subsidiaries and other affiliates
  • Service providers
  • Partners (go-to-market, analytics)
  • Third-party platforms (when you connect them to our service)
  • Governmental authorities (where necessary)
  • An actual or potential buyer

We use cookies (but not for advertising)

  • We do not use advertising or targeting cookies
  • We use necessary cookies to run and improve our site and service
  • You can disable cookies but this can impact your use or access to certain parts of our site and service

Know your rights

You may have the following rights related to your PII:

  • Access, correct, and update
  • Object to or restrict processing
  • Opt-out of marketing
  • Be forgotten by Sentry
  • Withdraw your consent
  • Complain about us

If you have any questions or concerns about your privacy at Sentry, please email us at [email protected]

If you are a California resident, see our Supplemental notice .

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

What alternatives are there for C/C++ assignment operator (=) and equality operators (==) syntax?

C/C++ use = for assignment and == for equality comparision. For example, a snippet in C++ can be like this:

But this can lead to unwanted bugs when programmers accidentally make a typo. Consider this example:

This is a (very) common typo in C/C++, partly because the two operators are so similar.

So what are the alternatives?

  • language-design

kaya3's user avatar

  • 4 $\begingroup$ Whatever syntax you choose for these, you can prevent this exact mistake by not having assignment expressions at all. nuclear_code = 1234; can be a statement without nuclear_code = 1234 needing to be allowed as an expression; Python did this before eventually relenting and adding the assignment operator := . Another issue that works against C in this regard is the coercion to boolean; in Java, if(nuclear_code = 1234) would be a type error because the condition must be a boolean , not an int . $\endgroup$ –  kaya3 Commented May 21, 2023 at 10:27
  • $\begingroup$ @kaya3 while that is true, the C/C++ way of doing it is a separate question in itself. I think that this still need to be asked. $\endgroup$ –  justANewbie Commented May 21, 2023 at 10:48
  • $\begingroup$ Yes, nothing wrong with the question. Just pointing out that there are more approaches to addressing this issue than just the choice of syntax for the two operators ─ and indeed, some languages use the same syntax = for both things because the context determines whether it's a name binding or an equality check. $\endgroup$ –  kaya3 Commented May 21, 2023 at 12:02
  • $\begingroup$ so are you asking particularly about design strategies to prevent these kinds of mistakes? Because I don't see that represented in your title, and if you are (asking about that), it should be (represented in your title) $\endgroup$ –  starball Commented May 21, 2023 at 19:03
  • 3 $\begingroup$ Not syntax, but in Swift assignment expressions are of type void, so this error can't happen either. $\endgroup$ –  chrysante Commented May 21, 2023 at 21:36

17 Answers 17

Just throw unicode symbols at it (the apl way).

APL uses ← for assignment and = / ≡ for equality ( = is term-wise, ≡ is for the whole array). If you can afford to just throw Unicode at the problem, sometimes it's a fun solution :) really depends on how the language is meant to be written, though.

RubenVerg's user avatar

  • 1 $\begingroup$ Not just Unicode have those symbols. Some calculators' BASIC dialects use ← as assignment too, from their limited character set. $\endgroup$ –  Longinus Commented May 22, 2023 at 1:52
  • 1 $\begingroup$ Some dialects of Smalltalk use _ for assignment, because early versions of ASCII had an arrow at that codepoint. $\endgroup$ –  Bbrk24 Commented May 22, 2023 at 4:16
  • $\begingroup$ @Longinus sure, but nowadays SBCS's are basically just Unicode mappings. I'd assume modern implementations of those BASIC's just read the (potentially sbcs-encoded) file and then display it as Unicode. $\endgroup$ –  RubenVerg Commented May 22, 2023 at 5:03
  • $\begingroup$ I can't really tell if this answer is serious. If it is, how do you expect users to type these symbols? $\endgroup$ –  chrysante Commented May 27, 2023 at 20:29
  • 1 $\begingroup$ @chrysante It is completely serious. In Dyalog APL, you'd hit your APL key (backtick by default) and then [ . $\endgroup$ –  RubenVerg Commented May 27, 2023 at 21:27

Distinguish Assignment and Equality by Context

Some languages use = for both assignment and equality. The way the language differentiates the two use cases is by constraining the grammar so it's obvious which context is meant.

For instance, in BASIC, there is no such thing as an "expression statement", so if you write something like x=1 on a line by itself, the only possible interpretation is that you are assigning 1 to x . The alternative interpretation of "check if x is equal to 1 and discard the result" isn't an allowed interpretation in the language. This is in contrast to a language like C where both interpretations are legal (and thus, the compiler needs an additional symbol to disambiguate the two interpretations). Some languages also use a keyword like let or set to begin an assignment statement which can also help distinguish the two.

The advantage of having only one operator for both operations is that it simplifies the language. It also means that the compiler will never misinterpret your program because of a careless error. On the other hand, it is less expressive than languages that separate out the two operations. For instance, in C++, you can assign to variables within a condition or loop. In a language like BASIC, you cannot do this which may lead to more verbose code in some cases.

Isaiah's user avatar

Even though the OP sepcifically asks for different syntax to prevent this kind of error, I would make the case that a better approach is a semantic solution:

The reason why this error can occur in C++ (and in C for that matter) is that an assignment expression evaluates to a reference to the assigned variable ( int& in this case) and that int is implicitly convertible to bool (*). By changing either of these properties we can prevent this error.

If we forbid implicit narrowing conversions or just the implicit int -> bool conversion we are already fine. This however prevents the following common C idiom:

But I would argue that this alternative code is easier to understand and just as simple to write:

If we evaluate assignment expressions not to a reference to the assigned value but to void we also solve the problem, but this time we prevent this idiom:

However this is rarely used and confusing if not seen before, and the alternative

is not significantly more verbose (and much clearer), so I would argue that losing this idiom is also not much of a loss if not an improvement.

So in conclusion I argue that while either of the approaches solves the problem, both of them are reasonable in their on right and can prevent other possible code smells.

Also now you are free to choose whatever syntax you like without the restriction of having to solve this problem.

(*) On top of that, in clauses of if statements, also explicit conversions to bool are considered in C++. This rule exists so class authors can make conversions to bool explicit, which prevents implicit conversions from the custom type to integral types (via class X -> bool -> int ) while still allowing the class to be used as a condition in if statements, but in our case it makes matters worse.

chrysante's user avatar

  • 1 $\begingroup$ An alternative is only forbidding raw assignment in a boolean context. Extra-parentheses are cheap enough. Also, if a , b and/or c are long and/or expressions with side-effects, the rewrite will be quite cumbersome and not actually that trivial. $\endgroup$ –  Deduplicator Commented Jul 3, 2023 at 15:44
  • $\begingroup$ @Deduplicator If a , b or c are complex expressions, you can store them to temporaries. That's what the compiler does under the hood if you write a nested assignment expression anyhow. I agree that forbidding raw assignment in if-conditions is also a solution, but that does not prevent the error in other boolean expressions. $\endgroup$ –  chrysante Commented Jul 3, 2023 at 16:38

The Pascal way

i.e using := for assignment and = for equality check.

The example in the question can be written in Pascal as:

This is so harder to mistype the two.

  • 2 $\begingroup$ Just as a note about this, := was chosen because it looked a bit like the left-arrow symbol in mathematics, ⟸, but wouldn't be confused for "less than or equal to". Prolog uses :- for a similar reason. $\endgroup$ –  Pseudonym Commented May 22, 2023 at 1:02
  • 5 $\begingroup$ @Pseudonym I believe the := symbol exists in mathematics as well, and has the meaning of introducing the definition for a new variable. The double arrows, on the other hand, I've never seen used for anything besides implication. Might be a case of poorly internationalized syntax, though) $\endgroup$ –  abel1502 Commented May 27, 2023 at 16:26
  • $\begingroup$ That's what I am doing in my programming language, AEC . $\endgroup$ –  FlatAssembler Commented Jul 10, 2023 at 18:47

The GNU solution to the if(x = y) {} problem is to require double parenthesisation where only if((x = y)) {} is unambiguous. That said, to mean assignment, the = , := , <- and ← operators are common across many languages descending from C, Pascal and BASIC. Vale uses a set keyword to mean reassignment.

In languages where the concept of "(re)assignment" does not exist, like most Functional and Logical ones, it is not uncommon to see = be used both for bindings and as the equality binary operator, along with == . For instance, in a language lacking builtin mutation support, this code is unambiguous:

Some English-oriented languages, like CoffeeScript , also use a is keyword.

For completeness, are also common as inequality operators != , /= , <> , ≠ and isnt , all used in various languages.

Longinus's user avatar

Common Lisp

Most of the time when you need a variable, you'll use let .

There's also setf .

Equality checking looks like one of the following (depending on what exactly you want—there are more equality operators).

It's really hard to accidentally mix the two up.

Aman Grewal's user avatar

Use : , like JSON

Assignment and comparison have different purposes, return values, and allowed syntactic locations. Therefore, they should be represented with bigger differences than a single extra character.

The use of : for "assignments" is already fairly common and should be familiar to users:

  • JSON/object notation: uses colon to bind a value to a key.
  • English: like this list, where a colon associates a value or comment with an entry.

This gives you a one-character solution for assignment, leaves = free for equality, and should be immediately clear to readers.

BoppreH's user avatar

  • $\begingroup$ : is used for assignment in K and Q. $\endgroup$ –  Adám Commented Oct 11, 2023 at 21:51

It partly depends on the semantics of variables and the semantics of equality.

Some languages distinguish between intensional and extensional equality . One example of this might be a set of integers represented as a binary search tree. Two sets are intensionally equal if the trees have the same structure, but extensionally equal if the numbers in the sets are the same.

Yet other languages have different notions of equality testing that depends on whether or not they will coerce types. Does 3 == 3.0 in a dynamically typed language? Sometimes you want that and sometimes you don't.

Other languages have object identity, which is different from equality.

This is a lot of symbols for equality testing that you might need to invent! Common Lisp has four of them.

Logic languages have only one symbol = , and it means unification . Just looking at simple values like numbers for the moment, if you type X = Y , then it can mean several things:

  • If X is a free variable but Y has a value already bound to it, this assigns that value to X .
  • Same thing if Y is free but X is bound; this is left-assignment.
  • If X and Y are both bound, then this is an equality test.
  • If X and Y are both free, then this aliases the two variables together. A subsequent binding of X will automagically also bind Y .

In general, X and Y could be data structures with some bound and some unbound variables inside it, in which case the full unification algorithm is run.

Pseudonym's user avatar

In Assembly ( mov ) or more basic languages there is a keyword for assignment, such as:

I am personally not a fan of this because I prefer punctuation as operators, but this is an option that resolves ambiguity.

Or in Assembly:

CPlus's user avatar

Different Spellings

Other common variations for assignment are := and (so far unmentioned) <- . JavaScript is notorious for having many different comparison operators.

Vale has the interesting variation that x = 42 is only a variable declaration, and assignment must be written set x = 42 . I find, like the author, that I also write many more dclarations than assignments.

Different Semantics

A functional language, using static single assignments, or one using linear types , allows assignment only within bindings, which can be marked with let . Alternatively, since newer languages tend to discourage mutability and assignments, you could mark assignments with set , or do both. Since is is no longer than == and be or to no longer than := or <- , this could be valid syntax:

Davislor's user avatar

Modern programming languages like Go use the "="/":=" for assignment and "==" for the comparison. It gives a compile time error if you mistype "=" instead of "==". Another suggestion would be to use constants when comparing, but that wouldn't solve your problem with mistyping in C++.

user514's user avatar

  • $\begingroup$ Welcome to PLDI. How does your answer differ from justANewbie's answer? $\endgroup$ –  Isaiah Commented May 21, 2023 at 16:03
  • $\begingroup$ @Isaiah Pascal uses = for equality comparison, and Go uses == for equality comparison. The point is that Go allows = instead of := for assignment when it's not in an expression. This is also the same as Python ─ = is assignment but not an expression, := is an assignment expression, == is an equality comparison. $\endgroup$ –  kaya3 Commented May 21, 2023 at 17:53
  • 4 $\begingroup$ "Modern programming languages like F# use = for both bindings and equality." It's a bold move to make a blanket statement like "modern PLs do x " when they disagree with each other on how to do x . $\endgroup$ –  Longinus Commented May 22, 2023 at 1:56

Coming relatively out of left field is Swift’s pattern-matching operator ~= . It’s rarely written in source, instead the result of desugaring a switch or if case statement, but you could use it instead of == for regular equality comparison if you wanted to.

Bbrk24's user avatar

The original Smalltalk uses ← for assignment and = for equality. It also uses ↑ for return.

The original Smalltalk developed at Xerox used its own workstation developed at Xerox with its own CPU developed at Xerox and its own input devices (keyboard and mouse) developed at Xerox. Smalltalk was its own Operating System as well.

All this to say that it also had its own character set and character encoding.

When Smalltalk first was ported to other systems using the ASCII character encoding, it turned out that ASCII had the character ^ at the same code point where Smalltalk had ↑ , so all Smalltalk was rendered with ^ for return on machines that used ASCII. It still looks like an upwards arrow, so it still kind of works.

Assignment was not so lucky, though: where Smalltalk had ← , ASCII has _ , so all assignments in Smalltalk were rendered as _ in ASCII. This was somewhat unsatisfactory, so it was decided to change the language specification use := for assignment. However, some Smalltalks still accept _ even today.

Jörg W Mittag's user avatar

  • $\begingroup$ I mentioned this in a comment on another answer, but this is much more thorough (as is expected from the nature of comments). $\endgroup$ –  Bbrk24 Commented Jul 6, 2023 at 17:05

Use ,= or ;=

We could already understand ,= as the += -like version of , in C-style operators. And ;= looks less confusing, if you already merge , with ; .

user23013's user avatar

Most compiler have the decency to give you a warning if you use the wrong operator, or if the compiler isn't sure. For example, with a good C compiler I expect that

gives a warning. And if I really want to store 1234 and then examine whether it is zero, these compilers may allow

which tells the compiler "be quiet, I know what I'm doing".

Newer languages don't allow integers to be used as boolean values. So the first example might not compile if the = operator doesn't yield a result, or it yields an integer result which cannot be used in an "if" statement. That's assuming that

would be very rare.

You could use different pairs of tokens. := and =, or = and .eq. like FORTRAN did, or a leftarrow for assignment. The warning, and possible changed semantics, is the simplest solution. In the end, if the code you type is not the code you wanted, that's your problem.

gnasher729's user avatar

You can raise an error

For example this code in Python is correct:

raise an error (no confusing bug like C++):

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged syntax language-design ..

  • Featured on Meta
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...
  • We spent a sprint addressing your requests — here’s how it went

Hot Network Questions

  • The rear wheel from my new Road Bike vibrates strongly
  • Should I apologise to a professor after a gift authorship attempt, which they refused?
  • MOSFET Datasheet Confusion
  • Big zeros in block diagonal matrix
  • Error concerning projectile motion in respected textbook?
  • How can I get the value of the f(1/2) is 11/4 not 2.75 when I use \pgfmathprintnumber\pgfmathresult?
  • How can I remove rust stains from outdoor vinyl flooring?
  • Is ElGamal homomorphic encryption using additive groups works only for Discrete Log ElGamal? What about EC ElGamal?
  • Is "sinnate" a word? What does it mean?
  • What is the difference between 居る and 要る?
  • Schematic component
  • Can trills have 3 notes instead of two?
  • What does this mean in RISC-V opcode table
  • Understanding top memory bar
  • Has the Journal of Fluid Mechanics really published more than 800 volumes?
  • Are there other proposed translations of "aelfheres" in Beowulf than a name?
  • Intelligence vs Wisdom in D&D
  • Coincidence between coefficients of tanh(tan(x/2)) and Chow ring computations?
  • Animate multiple material transitions smoothly
  • Senior citizen ladies solve crimes
  • Why do jet aircraft need chocks when they have parking brakes?
  • Time integration of first-order ODE with higher-order information
  • Mathematical Induction over two numbers
  • Decomposing the homology of a finite-index subgroup into isotypic components

assignment operators equal

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Assignment operators (C# reference)

  • 11 contributors

The assignment operator = assigns the value of its right-hand operand to a variable, a property , or an indexer element given by its left-hand operand. The result of an assignment expression is the value assigned to the left-hand operand. The type of the right-hand operand must be the same as the type of the left-hand operand or implicitly convertible to it.

The assignment operator = is right-associative, that is, an expression of the form

is evaluated as

The following example demonstrates the usage of the assignment operator with a local variable, a property, and an indexer element as its left-hand operand:

The left-hand operand of an assignment receives the value of the right-hand operand. When the operands are of value types , assignment copies the contents of the right-hand operand. When the operands are of reference types , assignment copies the reference to the object.

This is called value assignment : the value is assigned.

ref assignment

Ref assignment = ref makes its left-hand operand an alias to the right-hand operand, as the following example demonstrates:

In the preceding example, the local reference variable arrayElement is initialized as an alias to the first array element. Then, it's ref reassigned to refer to the last array element. As it's an alias, when you update its value with an ordinary assignment operator = , the corresponding array element is also updated.

The left-hand operand of ref assignment can be a local reference variable , a ref field , and a ref , out , or in method parameter. Both operands must be of the same type.

Compound assignment

For a binary operator op , a compound assignment expression of the form

is equivalent to

except that x is only evaluated once.

Compound assignment is supported by arithmetic , Boolean logical , and bitwise logical and shift operators.

Null-coalescing assignment

You can use the null-coalescing assignment operator ??= to assign the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null . For more information, see the ?? and ??= operators article.

Operator overloadability

A user-defined type can't overload the assignment operator. However, a user-defined type can define an implicit conversion to another type. That way, the value of a user-defined type can be assigned to a variable, a property, or an indexer element of another type. For more information, see User-defined conversion operators .

A user-defined type can't explicitly overload a compound assignment operator. However, if a user-defined type overloads a binary operator op , the op= operator, if it exists, is also implicitly overloaded.

C# language specification

For more information, see the Assignment operators section of the C# language specification .

  • C# operators and expressions
  • ref keyword
  • Use compound assignment (style rules IDE0054 and IDE0074)

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .

Submit and view feedback for

Additional resources

21.12 — Overloading the assignment operator

Difference between equal to (==) and assignment operator (=) in Python

Difference between equal to (==) and assignment operator (=) in Python

In this article, we would discuss the difference between equal to (==) and assignment operator (=) in Python. In programming languages, we need to assign values to the variables this is achieved through assignment operator . Furthermore, to compare values stored in variables we use comparison operators. Want to know about comparison operators in Python ? equal to comes under the category of comparison operators.

If you have just started with Python then it may look confusing in the beginning. But, these are pretty easy to use once we understand what we are trying to achieve with both these operators. So, we start with the basic introduction followed by relevant examples.

Firstly, equal to (==) operator – as already discussed it is a comparison operator. It is used to check if two values/variables are equal. For instance, string “abc” is equal to string “abc” but not equal to string “xyz”. If the condition satisfies then, it returns with True otherwise False. In addition to, it won’t always be plain True/False outcome. At times, we would ask the interpreter to execute a specific code if a condition satisfies otherwise something else. Even for those cases, the equal to (==) operator works just fine.

Now, understand it with couple of examples next. We compare an integer with integer and then string with a string.

For both, it would return with True .

As expected, it returns with False . We go a step further and use if..else statement .

It would return with –

Note: Please take care of indentation in above code otherwise it would result in an error.

Here, if..else statement checks whether x is equal to 1 or not. And, shows the outcome accordingly. If you want to know more about if..else statement in Python .

Secondly, assignment (=) operator – these are used to assign values to the variable. If we want to write an efficient and clutter-free code then, we have to assign values to the variables. And, these variables can later be used to perform various operations. So, this is how it works –

Clearly, we assigned some value to x and y variables. Later, these we printed using print() method.

In conclusion , we have covered difference between equal to and assignment operators operator in Python here.

Similar Posts

Execute Python Scripts in Ubuntu

Execute Python Scripts in Ubuntu

In this article, we would discuss how to execute Python scripts in Ubuntu. A Python script contains an instruction set….

Install Python IDLE in Ubuntu 22.04

Install Python IDLE in Ubuntu 22.04

In this article, we would discuss how to install Python IDLE in Ubuntu 22.04 release. IDLE is the abbreviation for…

swapcase() in Python

swapcase() in Python

In this article, we would cover swapcase() method in Python. The swapcase() method basically converts all the uppercase characters to…

string find() in Python

string find() in Python

In this article, we would cover string find() method in Python. Sometimes, we need to find a substring which is…

items() method in Python Dictionary

items() method in Python Dictionary

In this article, we would cover items() method in Python Dictionary. The items() method returns with a view object. Or,…

Install Python 3.10.2 in Ubuntu 22.04

Install Python 3.10.2 in Ubuntu 22.04

Python is an object-oriented, high-level, interpreted programming language. Guido van Rossum created it. The programming language first appeared in the…

Introduction

Some operators are used to build expressions returning a result:

Arithmetic operators

Comparison operators, logical operators.

  • The ?: ternary operator
  • The [] history-referencing operator

Other operators are used to assign values to variables:

  • = is used to assign a value to a variable, but only when you declare the variable (the first time you use it)
  • := is used to assign a value to a previously declared variable . The following operators can also be used in such a way: += , -= , *= , /= , %=

As is explained in the Type system page, qualifiers and types play a critical role in determining the type of results that expressions yield. This, in turn, has an impact on how and with what functions you will be allowed to use those results. Expressions always return a value with the strongest qualifier used in the expression, e.g., if you multiply an “input int” with a “series int”, the expression will produce a “series int” result, which you will not be able to use as the argument to length in ta.ema() .

This script will produce a compilation error:

The compiler will complain: Cannot call ‘ta.ema’ with argument ‘length’=‘adjustedLength’. An argument of ‘series int’ type was used but a ‘simple int’ is expected; . This is happening because lenInput is an “input int” but factor is a “series int” (it can only be determined by looking at the value of year on each bar). The adjustedLength variable is thus assigned a “series int” value. Our problem is that the Reference Manual entry for ta.ema() tells us that its length parameter requires a “simple” value, which is a weaker qualifier than “series”, so a “series int” value is not allowed.

The solution to our conundrum requires:

  • Using another moving average function that supports a “series int” length, such as ta.sma() , or
  • Not using a calculation producing a “series int” value for our length.

There are five arithmetic operators in Pine Script™:

OperatorMeaning
Addition and string concatenation
Subtraction
Multiplication
Division
Modulo (remainder after division)

The arithmetic operators above are all binary (means they need two operands — or values — to work on, like in 1 + 2 ). The + and - also serve as unary operators (means they work on one operand, like -1 or +1 ).

If both operands are numbers but at least one of these is of float type, the result will also be a float . If both operands are of int type, the result will also be an int . If at least one operand is na , the result is also na .

The + operator also serves as the concatenation operator for strings. "EUR"+"USD" yields the "EURUSD" string.

The % operator calculates the modulo by rounding down the quotient to the lowest possible value. Here is an easy example that helps illustrate how the modulo is calculated behind the scenes:

There are six comparison operators in Pine Script™:

OperatorMeaning
Less Than
Less Than or Equal To
Not Equal
Equal
Greater Than
Greater Than or Equal To

Comparison operations are binary. If both operands have a numerical value, the result will be of type bool , i.e., true , false or na .

There are three logical operators in Pine Script™:

OperatorMeaning
Negation
Logical Conjunction
Logical Disjunction

The operator not is unary. When applied to a true , operand the result will be false , and vice versa.

and operator truth table:

aba and b
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

or operator truth table:

aba or b
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

`?:` ternary operator

The ?: ternary operator is used to create expressions of the form:

The ternary operator returns a result that depends on the value of condition . If it is true , then valueWhenConditionIsTrue is returned. If condition is false or na , then valueWhenConditionIsFalse is returned.

A combination of ternary expressions can be used to achieve the same effect as a switch structure, e.g.:

The example is calculated from left to right:

  • If timeframe.isintraday is true , then color.red is returned. If it is false , then timeframe.isdaily is evaluated.
  • If timeframe.isdaily is true , then color.green is returned. If it is false , then timeframe.ismonthly is evaluated.
  • If timeframe.ismonthly is true , then color.blue is returned, otherwise na is returned.

Note that the return values on each side of the : are expressions --- not local blocks, so they will not affect the limit of 500 local blocks per scope.

`[ ]` history-referencing operator

It is possible to refer to past values of time series using the [] history-referencing operator. Past values are values a variable had on bars preceding the bar where the script is currently executing — the current bar . See the Execution model page for more information about the way scripts are executed on bars.

The [] operator is used after a variable, expression or function call. The value used inside the square brackets of the operator is the offset in the past we want to refer to. To refer to the value of the volume built-in variable two bars away from the current bar, one would use volume[2] .

Because series grow dynamically, as the script moves on sucessive bars, the offset used with the operator will refer to different bars. Let’s see how the value returned by the same offset is dynamic, and why series are very different from arrays. In Pine Script™, the close variable, or close[0] which is equivalent, holds the value of the current bar’s “close”. If your code is now executing on the third bar of the dataset (the set of all bars on your chart), close will contain the price at the close of that bar, close[1] will contain the price at the close of the preceding bar (the dataset’s second bar), and close[2] , the first bar. close[3] will return na because no bar exists in that position, and thus its value is not available .

When the same code is executed on the next bar, the fourth in the dataset, close will now contain the closing price of that bar, and the same close[1] used in your code will now refer to the “close” of the third bar in the dataset. The close of the first bar in the dataset will now be close[3] , and this time close[4] will return na .

In the Pine Script™ runtime environment, as your code is executed once for each historical bar in the dataset, starting from the left of the chart, Pine Script™ is adding a new element in the series at index 0 and pushing the pre-existing elements in the series one index further away. Arrays, in comparison, can have constant or variable sizes, and their content or indexing structure is not modified by the runtime environment. Pine Script™ series are thus very different from arrays and only share familiarity with them through their indexing syntax.

When the market for the chart’s symbol is open and the script is executing on the chart’s last bar, the realtime bar , close returns the value of the current price. It will only contain the actual closing price of the realtime bar the last time the script is executed on that bar, when it closes.

Pine Script™ has a variable that contains the number of the bar the script is executing on: bar_index . On the first bar, bar_index is equal to 0 and it increases by 1 on each successive bar the script executes on. On the last bar, bar_index is equal to the number of bars in the dataset minus one.

There is another important consideration to keep in mind when using the [] operator in Pine Script™. We have seen cases when a history reference may return the na value. na represents a value which is not a number and using it in any expression will produce a result that is also na (similar to NaN ). Such cases often happen during the script’s calculations in the early bars of the dataset, but can also occur in later bars under certain conditions. If your code does not explicitly provide for handling these special cases, they can introduce invalid results in your script’s calculations which can ripple through all the way to the realtime bar. The na and nz functions are designed to allow for handling such cases.

These are all valid uses of the [] operator:

Note that the [] operator can only be used once on the same value. This is not allowed:

Operator precedence

The order of calculations is determined by the operators’ precedence. Operators with greater precedence are calculated first. Below is a list of operators sorted by decreasing precedence:

PrecedenceOperator
9
8unary , unary ,
7 , ,
6 ,
5 , , ,
4 ,
3
2
1

If in one expression there are several operators with the same precedence, then they are calculated left to right.

If the expression must be calculated in a different order than precedence would dictate, then parts of the expression can be grouped together with parentheses.

`=` assignement operator

The = operator is used to assign a variable when it is initialized --- or declared ---, i.e., the first time you use it. It says this is a new variable that I will be using, and I want it to start on each bar with this value .

These are all valid variable declarations:

See the Variable declarations page for more information on how to declare variables.

`:=` reassignement operator

The := is used to reassign a value to an existing variable. It says use this variable that was declared earlier in my script, and give it a new value .

Variables which have been first declared, then reassigned using := , are called mutable variables. All the following examples are valid variable reassignments. You will find more information on how var works in the section on the `var` declaration mode :

  • We declare pHi with this code: var float pHi = na . The var keyword tells Pine Script™ that we only want that variable initialized with na on the dataset’s first bar. The float keyword tells the compiler we are declaring a variable of type “float”. This is necessary because, contrary to most cases, the compiler cannot automatically determine the type of the value on the right side of the = sign.
  • While the variable declaration will only be executed on the first bar because it uses var , the pHi := nz(ta.pivothigh(5, 5), pHi) line will be executed on all the chart’s bars. On each bar, it evaluates if the pivothigh() call returns na because that is what the function does when it hasn’t found a new pivot. The nz() function is the one doing the “checking for na ” part. When its first argument ( ta.pivothigh(5, 5) ) is na , it returns the second argument ( pHi ) instead of the first. When pivothigh() returns the price point of a newly found pivot, that value is assigned to pHi . When it returns na because no new pivot was found, we assign the previous value of pHi to itself, in effect preserving its previous value.

The output of our script looks like this:

image

  • The line preserves its previous value until a new pivot is found.
  • Pivots are detected five bars after the pivot actually occurs because our ta.pivothigh(5, 5) call says that we require five lower highs on both sides of a high point for it to be detected as a pivot.

See the Variable reassignment section for more information on how to reassign values to variables.

Identifiers

Variable declarations.

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

What does ":=" do?

I've seen := used in several code samples, but never with an accompanying explanation. It's not exactly possible to google its use without knowing the proper name for it.

What does it do?

  • colon-equals

moodymudskipper's user avatar

  • 17 In what language? –  Beta Commented Mar 17, 2011 at 20:17
  • 4 You normally use := when you define something, to separate it from regular variable changes.. What programming language are we talking about? –  svens Commented Mar 17, 2011 at 20:18
  • 4 PL/SQL it is for assignment. But given a different language, that answer isn't guarenteed to hold true - so which languages was the example in? –  Andrew Commented Mar 17, 2011 at 20:18
  • 15 To google something like this, spell it out and enclose it in quotes, like so: "colon equals" –  Intelekshual Commented Mar 17, 2011 at 20:20
  • 3 I think Pascal's got this operator ! –  user1899812 Commented Sep 30, 2013 at 15:08

12 Answers 12

http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming

In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ to denote their assignment operator. Languages making the latter choice often use a double equals sign (==) to denote their boolean equality operator.

Note: I found this by searching for colon equals operator

drudge's user avatar

  • 71 Ironically, this answer is now above Wikipedia when searching for colon equals operator . –  nighthawk454 Commented Feb 19, 2015 at 18:59
  • 7 If we keep typing colon equals operator , we work magic on Google's SEO to make this the top result –  ATLUS Commented Feb 4, 2016 at 7:23
  • That link looks old. Here's the updated link (I think), but the quote seems to be massively changed since then and I can't track down the new quote exactly: en.wikipedia.org/wiki/Assignment_(computer_science) . –  Gabriel Staples Commented Mar 7, 2021 at 23:57
  • Smalltalk was also an influential language that used the colon equals operator for assignment. –  fzwo Commented Jul 28, 2022 at 21:34

It's the assignment operator in Pascal and is often used in proofs and pseudo-code. It's the same thing as = in C-dialect languages.

Historically, computer science papers used = for equality comparisons and ← for assignments. Pascal used := to stand in for the hard-to-type left arrow. C went a different direction and instead decided on the = and == operators.

John Kugelman's user avatar

In the statically typed language Go := is initialization and assignment in one step. It is done to allow for interpreted-like creation of variables in a compiled language.

Matias Forbord's user avatar

Another interpretation from outside the world of programming languages comes from Wolfram Mathworld , et al:

If A and B are equal by definition (i.e., A is defined as B), then this is written symbolically as A=B, A:=B, or sometimes A≜B.

■ http://mathworld.wolfram.com/Defined.html

■ https://math.stackexchange.com/questions/182101/appropriate-notation-equiv-versus

RBV's user avatar

Some language uses := to act as the assignment operator.

Mike Lewis's user avatar

  • @Pacerier see this post stackoverflow.com/questions/7462322/… as to why the answer to your question can be both "Yes" and "No". –  TigOldBitties Commented Apr 2, 2015 at 18:26
  • @TigOldBitties, Good gotcha from Erwin down there. –  Pacerier Commented Apr 6, 2015 at 14:27

In a lot of CS books, it's used as the assignment operator, to differentiate from the equality operator = . In a lot of high level languages, though, assignment is = and equality is == .

gailbear's user avatar

This is old (pascal) syntax for the assignment operator. It would be used like so:

It may be in other languages as well, probably in a similar use.

mklauber's user avatar

A number of programming languages, most notably Pascal and Ada , use a colon immediately followed by an equals sign ( := ) as the assignment operator , to distinguish it from a single equals which is an equality test (C instead used a single equals as assignment, and a double equals as the equality test).

Reference: Colon (punctuation) .

Wenfang Du's user avatar

In Python :

Named Expressions ( NAME := expr ) was introduced in Python 3.8. It allows for the assignment of variables within an expression that is currently being evaluated. The colon equals operator := is sometimes called the walrus operator because, well, it looks like a walrus emoticon.

For example:

This would be invalid if you swapped the := for = . Note the additional parentheses surrounding the named expression. Another example:

Note that the variable total is not local to the comprehension (so too is comment from the first example). The NAME in a named expression cannot be a local variable within an expression, so, for example, [i := 0 for i, j in stuff] would be invalid, because i is local to the list comprehension.

I've taken examples from the PEP 572 document - it's a good read! I for one am looking forward to using Named Expressions, once my company upgrades from Python 3.6. Hope this was helpful!

Sources: Towards Data Science Article and PEP 572 .

Eugene's user avatar

It's like an arrow without using a less-than symbol <= so like everybody already said "assignment" operator. Bringing clarity to what is being set to where as opposed to the logical operator of equivalence.

In Mathematics it is like equals but A := B means A is defined as B, a triple bar equals can be used to say it's similar and equal by definition but not always the same thing.

Anyway I point to these other references that were probably in the minds of those that invented it, but it's really just that plane equals and less that equals were taken (or potentially easily confused with =<) and something new to define assignment was needed and that made the most sense.

Historical References: I first saw this in SmallTalk the original Object Language, of which SJ of Apple only copied the Windows part of and BG of Microsoft watered down from them further (single threaded). Eventually SJ in NeXT took the second more important lesson from Xerox PARC in, which became Objective C.

Well anyway they just took colon-equals assiment operator from ALGOL 1958 which was later popularized by Pascal

https://en.wikipedia.org/wiki/PARC_(company)

https://en.wikipedia.org/wiki/Assignment_(computer_science)

Assignments typically allow a variable to hold different values at different times during its life-span and scope. However, some languages (primarily strictly functional) do not allow that kind of "destructive" reassignment, as it might imply changes of non-local state. The purpose is to enforce referential transparency, i.e. functions that do not depend on the state of some variable(s), but produce the same results for a given set of parametric inputs at any point in time.

https://en.wikipedia.org/wiki/Referential_transparency

Master James's user avatar

For VB.net,

a constructor (for this case, Me = this in Java):

when you create that object:

Then, regardless of the order of the parameters, that ABC object has A=2, B=3, C=1

So, ya, very good practice for others to read your code effectively

Near's user avatar

Colon-equals was used in Algol and its descendants such as Pascal and Ada because it is as close as ASCII gets to a left-arrow symbol.

The strange convention of using equals for assignment and double-equals for comparison was started with the C language.

In Prolog, there is no distinction between assignment and the equality test.

Michael restore Monica Cellio's user avatar

  • 2 If they wanted it close to the left arrow, they could have used <- like Haskell did. They weren't trying to get close to the left arrow with := , they were using the mathematical 'is defined as' operator: mathworld.wolfram.com/Defined.html –  Variadicism Commented Apr 17, 2016 at 8:46
  • 1 Pedant alert: <- in Haskell is not assignment. Haskell does not have destructive assignment in the way of Pascal, Ada etc. <- is part of the do-notation syntax for parameter substitution. It is more analogous to the process of substituting values into parameters in a subroutine call. –  Michael restore Monica Cellio Commented Apr 20, 2016 at 10:41
  • 1 @Michael Fair enough. You're right. My bad. Anyway, the point remains that if they were trying to imitate the left arrow, they would not have used := , they would have used <- . –  Variadicism Commented Aug 16, 2016 at 19:52

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged operators colon-equals or ask your own question .

  • Featured on Meta
  • We spent a sprint addressing your requests — here’s how it went
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...
  • What makes a homepage useful for logged-in users

Hot Network Questions

  • Is it an option for the ls utility specified in POSIX.1-2017?
  • What caused the builder to change plans midstream on this 1905 library in New England?
  • Can I prettify a XML string using Apex?
  • Senior citizen ladies solve crimes
  • Intelligence vs Wisdom in D&D
  • What scientifically plausible apocalypse scenario, if any, meets my criteria?
  • DNS Stopped resolving on upgrade to Ubuntu 23.10 and Ubuntu 24.04
  • Is ElGamal homomorphic encryption using additive groups works only for Discrete Log ElGamal? What about EC ElGamal?
  • How is 11:22 four minutes slow if it's actually 11:29?
  • How should I deal with curves in new deck boards during installation?
  • Can I set QGIS to summarize icons above a certain scale and display only the number of icons in an area?
  • Can computer components be damaged if they stay off for a long time?
  • Sci fi book that has a tunnel. Depending on where you go through wall, go to different planet
  • Coincidence between coefficients of tanh(tan(x/2)) and Chow ring computations?
  • Interesting structure: ".....ever go to do... ! --- "If you ever go to sell this place, let me know."
  • Has the Journal of Fluid Mechanics really published more than 800 volumes?
  • Why does King Aegon speak to his dragon in the Common Tongue (English)?
  • Does the cosmological constant entail a mass for the graviton?
  • Animate multiple material transitions smoothly
  • Signature of Rav Ovadia Hedaya
  • I want to pick my flight route. I can either get 2 round trip tickets (SRC<->MID, MID<->DST) or 3rd party booking (SRC<->DST). Which is more reliable?
  • If someone clearly believes that he has witnessed something extraordinary very clearly, why is it more reasonable to believe that they hallucinated?
  • Another board component that I need help identifying
  • The rear wheel from my new Road Bike vibrates strongly

assignment operators equal

Wastewater operator: Exam

Wastewater exams are offered at this location. You must pre-register (no walk-ins).

Date and location are tentative.

Exam application and payment must be postmarked by January 22, 2025.

  • Wastewater certification exam: Application form (wq-wwtp8-00)

Related events

  • Python Basics
  • Interview Questions
  • Python Quiz
  • Popular Packages
  • Python Projects
  • Practice Python
  • AI With Python
  • Learn Python3
  • Python Automation
  • Python Web Dev
  • DSA with Python
  • Python OOPs
  • Dictionaries
  • Python Operators
  • Precedence and Associativity of Operators in Python
  • Python Arithmetic Operators
  • Difference between / vs. // operator in Python
  • Python - Star or Asterisk operator ( * )
  • What does the Double Star operator mean in Python?
  • Division Operators in Python
  • Modulo operator (%) in Python
  • Python Logical Operators
  • Python OR Operator
  • Difference between 'and' and '&' in Python
  • not Operator in Python | Boolean Logic
  • Ternary Operator in Python
  • Python Bitwise Operators

Python Assignment Operators

Assignment operators in python.

  • Walrus Operator in Python 3.8
  • Increment += and Decrement -= Assignment Operators in Python
  • Merging and Updating Dictionary Operators in Python 3.9
  • New '=' Operator in Python3.8 f-string

Python Relational Operators

  • Comparison Operators in Python
  • Python NOT EQUAL operator
  • Difference between == and is operator in Python
  • Chaining comparison operators in Python
  • Python Membership and Identity Operators
  • Difference between != and is not operator in Python

The Python Operators are used to perform operations on values and variables. These are the special symbols that carry out arithmetic, logical, and bitwise computations. The value the operator operates on is known as the Operand. Here, we will cover Different Assignment operators in Python .

Operators

=

Assign the value of the right side of the expression to the left side operandc = a + b 


+=

Add right side operand with left side operand and then assign the result to left operanda += b   

-=

Subtract right side operand from left side operand and then assign the result to left operanda -= b  


*=

Multiply right operand with left operand and then assign the result to the left operanda *= b     


/=

Divide left operand with right operand and then assign the result to the left operanda /= b


%=

Divides the left operand with the right operand and then assign the remainder to the left operanda %= b  


//=

Divide left operand with right operand and then assign the value(floor) to left operanda //= b   


**=

Calculate exponent(raise power) value using operands and then assign the result to left operanda **= b     


&=

Performs Bitwise AND on operands and assign the result to left operanda &= b   


|=

Performs Bitwise OR on operands and assign the value to left operanda |= b    


^=

Performs Bitwise XOR on operands and assign the value to left operanda ^= b    


>>=

Performs Bitwise right shift on operands and assign the result to left operanda >>= b     


<<=

Performs Bitwise left shift on operands and assign the result to left operanda <<= b 


:=

Assign a value to a variable within an expression

a := exp

Here are the Assignment Operators in Python with examples.

Assignment Operator

Assignment Operators are used to assign values to variables. This operator is used to assign the value of the right side of the expression to the left side operand.

Addition Assignment Operator

The Addition Assignment Operator is used to add the right-hand side operand with the left-hand side operand and then assigning the result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the addition assignment operator which will first perform the addition operation and then assign the result to the variable on the left-hand side.

S ubtraction Assignment Operator

The Subtraction Assignment Operator is used to subtract the right-hand side operand from the left-hand side operand and then assigning the result to the left-hand side operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the subtraction assignment operator which will first perform the subtraction operation and then assign the result to the variable on the left-hand side.

M ultiplication Assignment Operator

The Multiplication Assignment Operator is used to multiply the right-hand side operand with the left-hand side operand and then assigning the result to the left-hand side operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the multiplication assignment operator which will first perform the multiplication operation and then assign the result to the variable on the left-hand side.

D ivision Assignment Operator

The Division Assignment Operator is used to divide the left-hand side operand with the right-hand side operand and then assigning the result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the division assignment operator which will first perform the division operation and then assign the result to the variable on the left-hand side.

M odulus Assignment Operator

The Modulus Assignment Operator is used to take the modulus, that is, it first divides the operands and then takes the remainder and assigns it to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the modulus assignment operator which will first perform the modulus operation and then assign the result to the variable on the left-hand side.

F loor Division Assignment Operator

The Floor Division Assignment Operator is used to divide the left operand with the right operand and then assigs the result(floor value) to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the floor division assignment operator which will first perform the floor division operation and then assign the result to the variable on the left-hand side.

Exponentiation Assignment Operator

The Exponentiation Assignment Operator is used to calculate the exponent(raise power) value using operands and then assigning the result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the exponentiation assignment operator which will first perform exponent operation and then assign the result to the variable on the left-hand side.

Bitwise AND Assignment Operator

The Bitwise AND Assignment Operator is used to perform Bitwise AND operation on both operands and then assigning the result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the bitwise AND assignment operator which will first perform Bitwise AND operation and then assign the result to the variable on the left-hand side.

Bitwise OR Assignment Operator

The Bitwise OR Assignment Operator is used to perform Bitwise OR operation on the operands and then assigning result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the bitwise OR assignment operator which will first perform bitwise OR operation and then assign the result to the variable on the left-hand side.

Bitwise XOR Assignment Operator 

The Bitwise XOR Assignment Operator is used to perform Bitwise XOR operation on the operands and then assigning result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the bitwise XOR assignment operator which will first perform bitwise XOR operation and then assign the result to the variable on the left-hand side.

Bitwise Right Shift Assignment Operator

The Bitwise Right Shift Assignment Operator is used to perform Bitwise Right Shift Operation on the operands and then assign result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the bitwise right shift assignment operator which will first perform bitwise right shift operation and then assign the result to the variable on the left-hand side.

Bitwise Left Shift Assignment Operator

The Bitwise Left Shift Assignment Operator is used to perform Bitwise Left Shift Opertator on the operands and then assign result to the left operand.

Example: In this code we have two variables ‘a’ and ‘b’ and assigned them with some integer value. Then we have used the bitwise left shift assignment operator which will first perform bitwise left shift operation and then assign the result to the variable on the left-hand side.

Walrus Operator

The Walrus Operator in Python is a new assignment operator which is introduced in Python version 3.8 and higher. This operator is used to assign a value to a variable within an expression.

Example: In this code, we have a Python list of integers. We have used Python Walrus assignment operator within the Python while loop . The operator will solve the expression on the right-hand side and assign the value to the left-hand side operand ‘x’ and then execute the remaining code.

author

Please Login to comment...

Similar reads.

  • Python-Operators

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

You are using an unsupported browser ×

You are using an unsupported browser. This web site is designed for the current versions of Microsoft Edge, Google Chrome, Mozilla Firefox, or Safari.

Site Feedback

The Office of the Federal Register publishes documents on behalf of Federal agencies but does not have any authority over their programs. We recommend you directly contact the agency associated with the content in question.

If you have comments or suggestions on how to improve the www.ecfr.gov website or have questions about using www.ecfr.gov, please choose the 'Website Feedback' button below.

If you would like to comment on the current content, please use the 'Content Feedback' button below for instructions on contacting the issuing agency

Website Feedback

  • Incorporation by Reference
  • Recent Updates
  • Recent Changes
  • Corrections
  • Reader Aids Home
  • Using the eCFR Point-in-Time System
  • Understanding the eCFR
  • Government Policy and OFR Procedures
  • Developer Resources
  • My Subscriptions
  • Sign In / Sign Up

Hi, Sign Out

The Electronic Code of Federal Regulations

Enhanced content :: cross reference.

Enhanced content is provided to the user to provide additional context.

Navigate by entering citations or phrases (eg: suggestions#fillExample" class="example badge badge-info">1 CFR 1.1 suggestions#fillExample" class="example badge badge-info">49 CFR 172.101 suggestions#fillExample" class="example badge badge-info">Organization and Purpose suggestions#fillExample" class="example badge badge-info">1/1.1 suggestions#fillExample" class="example badge badge-info">Regulation Y suggestions#fillExample" class="example badge badge-info">FAR ).

Choosing an item from citations and headings will bring you directly to the content. Choosing an item from full text search results will bring you to those results. Pressing enter in the search box will also bring you to search results.

Background and more details are available in the Search & Navigation guide.

  • Title 43 —Public Lands: Interior
  • Subtitle B —Regulations Relating to Public Lands
  • Chapter II —Bureau of Land Management, Department of the Interior
  • Subchapter C —Minerals Management (3000)
  • Part 3180 —Onshore Oil and Gas Unit Agreements: Unproven Areas
  • Appendix E to Part 3180

Enhanced Content - Table of Contents

The in-page Table of Contents is available only when multiple sections are being viewed.

Use the navigation links in the gray bar above to view the table of contents that this content belongs to.

Enhanced Content - Details

30 U.S.C. 189 .

48 FR 26766 , June 10, 1983, unless otherwise noted. Redesignated at 48 FR 36587 , Aug. 12, 1983.

Enhanced Content - Print

Generate PDF

This content is from the eCFR and may include recent changes applied to the CFR. The official, published CFR, is updated annually and available below under "Published Edition". You can learn more about the process here .

Enhanced Content - Display Options

The eCFR is displayed with paragraphs split and indented to follow the hierarchy of the document. This is an automated process for user convenience only and is not intended to alter agency intent or existing codification.

A separate drafting site is available with paragraph structure matching the official CFR formatting. If you work for a Federal agency, use this drafting site when drafting amendatory language for Federal regulations: switch to eCFR drafting site .

Enhanced Content - Subscribe

Subscribe to: Appendix E to Part 3180, Title 43

Enhanced Content - Timeline

  • 6/22/2024 view on this date view change introduced  

Enhanced Content - Go to Date

Enhanced content - compare dates, enhanced content - published edition.

View the most recent official publication:

  • View Title 43 on govinfo.gov
  • View the PDF for Appendix E to Part 3180, Title 43

These links go to the official, published CFR, which is updated annually. As a result, it may not include the most recent changes applied to the CFR. Learn more .

Enhanced Content - Developer Tools

This document is available in the following developer friendly formats:

  • Hierarchy JSON - Title 43
  • Content HTML - Appendix Appendix E to Part 3180
  • Content XML - Appendix Appendix E to Part 3180

Information and documentation can be found in our developer resources .

eCFR Content

The Code of Federal Regulations (CFR) is the official legal print publication containing the codification of the general and permanent rules published in the Federal Register by the departments and agencies of the Federal Government. The Electronic Code of Federal Regulations (eCFR) is a continuously updated online version of the CFR. It is not an official legal edition of the CFR.

Appendix E to Part 3180—Model for change in unit operator by assignment

Change in Unit Operator ______ Unit Area, County of ____________, State of ______________, No. __. This indenture, dated as of the ____________ day of ______________, 19____, by and between ____________________ hereinafter designated as “First Party,” and __________________ hereinafter designated as “Second Party.”

Witnesseth: Whereas under the provisions of the Act of February 25, 1920, 41 Stat. 437 30 U.S.C. secs. 181, et seq., as amended by the Act of August 8, 1946, 60 Stat. 950, the Department of the Interior, on the ____________ day of ______________, 19____, approved a unit agreement for the ______ Unit Area, wherein the First Party is designated as Unit Operator; and

Whereas the First Party desires to transfer, assign, release, and quitclaim, and the Second Party desires to assume all the rights, duties and obligations of Unit Operator under the unit agreement; and

Whereas for sufficient and valuable consideration, the receipt whereof is hereby acknowledged, the First Party has transferred, conveyed, and assigned all his/its rights under certain operating agreements involving lands within the area set forth in said unit agreement unto the Second Party;

Now, therefore, in consideration of the premises hereinbefore set forth, the First Party does hereby transfer, assign, release, and quitclaim unto Second Party all of First Party's rights, duties, and obligations as Unit Operator under said unit agreement; and

Second Party hereby accepts this assignment and hereby covenants and agrees to fulfill the duties and assume the obligations of Unit Operator under and pursuant to all the terms of said unit agreement to the full extent set forth in this assignment, effective upon approval of this indenture by the (Name and Title of authorized officer, BLM); said unit agreement being hereby incorporated herein by reference and made a part hereof as fully and effectively as though said unit agreement were expressly set forth in this instrument.

In witness whereof, the parties hereto have executed this instrument as of the date hereinabove set forth.

(Witnesses)

(First Party)

(Second Party)

I hereby approve the foregoing indenture designating ______ as Unit Operator under the unit agreement for the ______ Unit Area, this ____________ day of __________________, 19____.

Authorized officer of the Bureau of Land Management

[ 48 FR 26766 , June 10, 1983. Redesignated at 89 FR 31005 , Apr. 23, 2024]

Reader Aids

Information.

  • About This Site
  • Legal Status
  • Accessibility
  • No Fear Act
  • Continuity Information

IMAGES

  1. Assignment Operators in C with Examples

    assignment operators equal

  2. Assignment Operators in JavaScript (Hindi)

    assignment operators equal

  3. Assignment Operators

    assignment operators equal

  4. PPT

    assignment operators equal

  5. Difference between Assignment Operators and Equal Operators

    assignment operators equal

  6. 📔 Day 3

    assignment operators equal

VIDEO

  1. Python Comparison operators || Equal ( == ), Not equal ( != ) and Greater than

  2. 10 equal and assignment, and, or, not operator

  3. 25- C#

  4. Core

  5. Assignment Operators

  6. Relational Operators

COMMENTS

  1. What is the difference between = (Assignment) and == (Equal to) operators

    The differences can be shown in tabular form as follows: =. ==. It is an assignment operator. It is a relational or comparison operator. It is used for assigning the value to a variable. It is used for comparing two values. It returns 1 if both the values are equal otherwise returns 0. Constant term cannot be placed on left hand side.

  2. Assignment operators

    Assignment performs implicit conversion from the value of rhs to the type of lhs and then replaces the value in the object designated by lhs with the converted value of rhs . Assignment also returns the same value as what was stored in lhs (so that expressions such as a = b = c are possible). The value category of the assignment operator is non ...

  3. Assignment Operators in Programming

    Assignment operators are used in programming to assign values to variables. We use an assignment operator to store and update data within a program. They enable programmers to store data in variables and manipulate that data. The most common assignment operator is the equals sign (=), which assigns the value on the right side of the operator to ...

  4. Assignment operators

    for assignments to class type objects, the right operand could be an initializer list only when the assignment is defined by a user-defined assignment operator. removed user-defined assignment constraint. CWG 1538. C++11. E1 ={E2} was equivalent to E1 = T(E2) ( T is the type of E1 ), this introduced a C-style cast. it is equivalent to E1 = T{E2}

  5. Assignment Operators In C++

    In C++, the assignment operator forms the backbone of many algorithms and computational processes by performing a simple operation like assigning a value to a variable. It is denoted by equal sign ( = ) and provides one of the most basic operations in any programming language that is used to assign some value to the variables in C++ or in other ...

  6. C++ Assignment Operators

    Assignment Operators. Assignment operators are used to assign values to variables. In the example below, we use the assignment operator ( =) to assign the value 10 to a variable called x:

  7. Assignment Operators in C

    Simple assignment operator. Assigns values from right side operands to left side operand. C = A + B will assign the value of A + B to C. +=. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A. -=.

  8. Assignment (=)

    The assignment operator is completely different from the equals (=) sign used as syntactic separators in other locations, which include:Initializers of var, let, and const declarations; Default values of destructuring; Default parameters; Initializers of class fields; All these places accept an assignment expression on the right-hand side of the =, so if you have multiple equals signs chained ...

  9. Operators

    The assignment operator (operator =, with one equal sign) is not the same as the equality comparison operator (operator ==, with two equal signs); the first one (=) assigns the value on the right-hand to the variable on its left, while the other (==) compares whether the values on both sides of the operator are equal.

  10. C Programming Course Notes

    The Simple Assignment Operator. The equals sign, =, is known as the assignment operator in C; ... For operators of equal precedence, most operators are evaluated from left to right. Ex: What is the value of the expression 5 / 3 * 2.0 ?

  11. Difference between = (Assignment) and == (Equal to) operators in C

    Conclusion. So it's cleared now, , both are not same, = is an Assignment Operator it is used to assign the value of variable or expression, while == is an Equal to Operator and it is a relation operator used for comparison (to compare value of both left and right side operands).

  12. What's the Difference Between the Assignment (`=`) and Equality

    The = is an assignment operator, while == and === are called equality operators. Assignment Operator (=) In mathematics and algebra, = is an equal to operator. In programming = is an assignment operator, which means that it assigns a value to a variable. For example, the following code will store a value of 5 in the variable x:

  13. What are the differences between "=" and "<-" assignment operators?

    The operators <- and = assign into the environment in which they are evaluated. The operator <- can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions.

  14. Assignment Operators in C

    Different types of assignment operators are shown below: 1. "=": This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example: a = 10; b = 20; ch = 'y'; 2. "+=": This operator is combination of '+' and '=' operators. This operator first adds the current ...

  15. What alternatives are there for C/C++ assignment operator (=) and

    That said, to mean assignment, the =, :=, <-and ← operators are common across many languages descending from C, Pascal and BASIC. Vale uses a set keyword to mean reassignment. In languages where the concept of "(re)assignment" does not exist, like most Functional and Logical ones, it is not uncommon to see = be used both for bindings and as ...

  16. Assignment operators

    In this article. The assignment operator = assigns the value of its right-hand operand to a variable, a property, or an indexer element given by its left-hand operand. The result of an assignment expression is the value assigned to the left-hand operand. The type of the right-hand operand must be the same as the type of the left-hand operand or ...

  17. 21.12

    21.12 — Overloading the assignment operator. Alex November 27, 2023. The copy assignment operator (operator=) is used to copy values from one object to another already existing object. As of C++11, C++ also supports "Move assignment". We discuss move assignment in lesson 22.3 -- Move constructors and move assignment .

  18. Difference between equal to (==) and assignment operator ...

    Difference between equal to (==) and assignment operator (=) in Python. Firstly, equal to (==) operator - as already discussed it is a comparison operator. It is used to check if two values/variables are equal. For instance, string "abc" is equal to string "abc" but not equal to string "xyz". If the condition satisfies then, it ...

  19. What are Operators in Programming?

    Operators in programming are symbols or keywords that represent computations or actions performed on operands. Operands can be variables, constants, or values, and the combination of operators and operands form expressions. Operators play a crucial role in performing various tasks, such as arithmetic calculations, logical comparisons, bitwise ...

  20. Language / Operators

    The arithmetic operators above are all binary (means they need two operands — or values — to work on, like in 1 + 2).The + and -also serve as unary operators (means they work on one operand, like -1 or +1).. If both operands are numbers but at least one of these is of float type, the result will also be a float.If both operands are of int type, the result will also be an int.

  21. operators

    In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ to ...

  22. Wastewater operator: Exam

    Wastewater operator: Exam. Wastewater exams are offered at this location. You must pre-register (no walk-ins). Date and location are tentative. Registration information. ... Minnesota Pollution Control Agency is an equal opportunity employer. ...

  23. Assignment Operators in Python

    Assignment Operator. Assignment Operators are used to assign values to variables. This operator is used to assign the value of the right side of the expression to the left side operand. Python. # Assigning values using # Assignment Operator a = 3 b = 5 c = a + b # Output print(c) Output. 8.

  24. Appendix E to Part 3180, Title 43 -- Model for change in unit operator

    Second Party hereby accepts this assignment and hereby covenants and agrees to fulfill the duties and assume the obligations of Unit Operator under and pursuant to all the terms of said unit agreement to the full extent set forth in this assignment, effective upon approval of this indenture by the (Name and Title of authorized officer, BLM ...