Specifications

Browser compatibility.

An assignment operator assigns a value to its left operand based on the value of its right operand.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

The basic assignment operator is equal ( = ), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x . The other assignment operators are usually shorthand for standard operations, as shown in the following definitions and examples.

Simple assignment operator is used to assign a value to a variable. The assignment operation evaluates to the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables. See the example.

Addition assignment

The addition assignment operator adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible. See the addition operator for more details.

Subtraction assignment

The subtraction assignment operator subtracts the value of the right operand from a variable and assigns the result to the variable. See the subtraction operator for more details.

Multiplication assignment

The multiplication assignment operator multiplies a variable by the value of the right operand and assigns the result to the variable. See the multiplication operator for more details.

Division assignment

The division assignment operator divides a variable by the value of the right operand and assigns the result to the variable. See the division operator for more details.

Remainder assignment

The remainder assignment operator divides a variable by the value of the right operand and assigns the remainder to the variable. See the remainder operator for more details.

Exponentiation assignment

The exponentiation assignment operator evaluates to the result of raising first operand to the power second operand. See the exponentiation operator for more details.

Left shift assignment

The left shift assignment operator moves the specified amount of bits to the left and assigns the result to the variable. See the left shift operator for more details.

Right shift assignment

The right shift assignment operator moves the specified amount of bits to the right and assigns the result to the variable. See the right shift operator for more details.

Unsigned right shift assignment

The unsigned right shift assignment operator moves the specified amount of bits to the right and assigns the result to the variable. See the unsigned right shift operator for more details.

Bitwise AND assignment

The bitwise AND assignment operator uses the binary representation of both operands, does a bitwise AND operation on them and assigns the result to the variable. See the bitwise AND operator for more details.

Bitwise XOR assignment

The bitwise XOR assignment operator uses the binary representation of both operands, does a bitwise XOR operation on them and assigns the result to the variable. See the bitwise XOR operator for more details.

Bitwise OR assignment

The bitwise OR assignment operator uses the binary representation of both operands, does a bitwise OR operation on them and assigns the result to the variable. See the bitwise OR operator for more details.

Left operand with another assignment operator

In unusual situations, the assignment operator (e.g. x += y ) is not identical to the meaning expression (here x = x + y ). When the left operand of an assignment operator itself contains an assignment operator, the left operand is evaluated only once. For example:

  • Arithmetic operators

Document Tags and Contributors

  • JavaScript basics
  • JavaScript first steps
  • JavaScript building blocks
  • Introducing JavaScript objects
  • Introduction
  • Grammar and types
  • Control flow and error handling
  • Loops and iteration
  • Expressions and operators
  • Numbers and dates
  • Text formatting
  • Regular expressions
  • Indexed collections
  • Keyed collections
  • Working with objects
  • Details of the object model
  • Using promises
  • Iterators and generators
  • Meta programming
  • JavaScript modules
  • Client-side web APIs
  • A re-introduction to JavaScript
  • JavaScript data structures
  • Equality comparisons and sameness
  • Inheritance and the prototype chain
  • Strict mode
  • JavaScript typed arrays
  • Memory Management
  • Concurrency model and Event Loop
  • References:
  • ArrayBuffer
  • AsyncFunction
  • Float32Array
  • Float64Array
  • GeneratorFunction
  • InternalError
  • Intl.Collator
  • Intl.DateTimeFormat
  • Intl.ListFormat
  • Intl.Locale
  • Intl.NumberFormat
  • Intl.PluralRules
  • Intl.RelativeTimeFormat
  • ReferenceError
  • SharedArrayBuffer
  • SyntaxError
  • Uint16Array
  • Uint32Array
  • Uint8ClampedArray
  • WebAssembly
  • decodeURI()
  • decodeURIComponent()
  • encodeURI()
  • encodeURIComponent()
  • parseFloat()
  • Array comprehensions
  • Bitwise operators
  • Comma operator
  • Comparison operators
  • Conditional (ternary) operator
  • Destructuring assignment
  • Expression closures
  • Generator comprehensions
  • Grouping operator
  • Legacy generator function expression
  • Logical operators
  • Object initializer
  • Operator precedence
  • (currently at stage 1) pipes the value of an expression into a function. This allows the creation of chained function calls in a readable manner. The result is syntactic sugar in which a function call with a single argument can be written like this:">Pipeline operator
  • Property accessors
  • Spread syntax
  • async function expression
  • class expression
  • delete operator
  • function expression
  • function* expression
  • in operator
  • new operator
  • void operator
  • Legacy generator function
  • async function
  • for await...of
  • for each...in
  • function declaration
  • import.meta
  • try...catch
  • Arrow functions
  • Default parameters
  • Method definitions
  • Rest parameters
  • The arguments object
  • constructor
  • element loaded from a different domain for which you violated the same-origin policy.">Error: Permission denied to access property "x"
  • InternalError: too much recursion
  • RangeError: argument is not a valid code point
  • RangeError: invalid array length
  • RangeError: invalid date
  • RangeError: precision is out of range
  • RangeError: radix must be an integer
  • RangeError: repeat count must be less than infinity
  • RangeError: repeat count must be non-negative
  • ReferenceError: "x" is not defined
  • ReferenceError: assignment to undeclared variable "x"
  • ReferenceError: can't access lexical declaration`X' before initialization
  • ReferenceError: deprecated caller or arguments usage
  • ReferenceError: invalid assignment left-hand side
  • ReferenceError: reference to undefined property "x"
  • SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated
  • SyntaxError: "use strict" not allowed in function with non-simple parameters
  • SyntaxError: "x" is a reserved identifier
  • SyntaxError: JSON.parse: bad parsing
  • SyntaxError: Malformed formal parameter
  • SyntaxError: Unexpected token
  • SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
  • SyntaxError: a declaration in the head of a for-of loop can't have an initializer
  • SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
  • SyntaxError: for-in loop head declarations may not have initializers
  • SyntaxError: function statement requires a name
  • SyntaxError: identifier starts immediately after numeric literal
  • SyntaxError: illegal character
  • SyntaxError: invalid regular expression flag "x"
  • SyntaxError: missing ) after argument list
  • SyntaxError: missing ) after condition
  • SyntaxError: missing : after property id
  • SyntaxError: missing ; before statement
  • SyntaxError: missing = in const declaration
  • SyntaxError: missing ] after element list
  • SyntaxError: missing formal parameter
  • SyntaxError: missing name after . operator
  • SyntaxError: missing variable name
  • SyntaxError: missing } after function body
  • SyntaxError: missing } after property list
  • SyntaxError: redeclaration of formal parameter "x"
  • SyntaxError: return not in function
  • SyntaxError: test for equality (==) mistyped as assignment (=)?
  • SyntaxError: unterminated string literal
  • TypeError: "x" has no properties
  • TypeError: "x" is (not) "y"
  • TypeError: "x" is not a constructor
  • TypeError: "x" is not a function
  • TypeError: "x" is not a non-null object
  • TypeError: "x" is read-only
  • TypeError: 'x' is not iterable
  • TypeError: More arguments needed
  • TypeError: Reduce of empty array with no initial value
  • TypeError: can't access dead object
  • TypeError: can't access property "x" of "y"
  • TypeError: can't assign to property "x" on "y": not an object
  • TypeError: can't define property "x": "obj" is not extensible
  • TypeError: can't delete non-configurable array element
  • TypeError: can't redefine non-configurable property "x"
  • TypeError: cannot use 'in' operator to search for 'x' in 'y'
  • TypeError: cyclic object value
  • TypeError: invalid 'instanceof' operand 'x'
  • TypeError: invalid Array.prototype.sort argument
  • TypeError: invalid arguments
  • TypeError: invalid assignment to const "x"
  • TypeError: property "x" is non-configurable and can't be deleted
  • TypeError: setting getter-only property "x"
  • TypeError: variable "x" redeclares argument
  • URIError: malformed URI sequence
  • Warning: -file- is being assigned a //# sourceMappingURL, but already has one
  • Warning: 08/09 is not a legal ECMA-262 octal constant
  • Warning: Date.prototype.toLocaleFormat is deprecated
  • Warning: JavaScript 1.6's for-each-in loops are deprecated
  • Warning: String.x is deprecated; use String.prototype.x instead
  • Warning: expression closures are deprecated
  • Warning: unreachable code after return statement
  • X.prototype.y called on incompatible type
  • JavaScript technologies overview
  • Lexical grammar
  • Enumerability and ownership of properties
  • Iteration protocols
  • Transitioning to strict mode
  • Template literals
  • Deprecated features
  • ECMAScript 2015 support in Mozilla
  • ECMAScript 5 support in Mozilla
  • Firefox JavaScript changelog
  • New in JavaScript 1.1
  • New in JavaScript 1.2
  • New in JavaScript 1.3
  • New in JavaScript 1.4
  • New in JavaScript 1.5
  • New in JavaScript 1.6
  • New in JavaScript 1.7
  • New in JavaScript 1.8
  • New in JavaScript 1.8.1
  • New in JavaScript 1.8.5
  • Documentation:
  • All pages index
  • Methods index
  • Properties index
  • Pages tagged "JavaScript"
  • JavaScript doc status
  • The MDN project

Learn the best of web development

Get the latest and greatest from MDN delivered straight to your inbox.

Thanks! Please check your inbox to confirm your subscription.

If you haven’t previously confirmed a subscription to a Mozilla-related newsletter you may have to do so. Please check your inbox or your spam filter for an email from us.

cppreference.com

Assignment operators.

Assignment and compound assignment operators are binary operators that modify the variable to their left using the value to their right.

[ edit ] Simple assignment

The simple assignment operator expressions have the form

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-lvalue (so that expressions such as ( a = b ) = c are invalid).

rhs and lhs must satisfy one of the following:

  • both lhs and rhs have compatible struct or union type, or..
  • rhs must be implicitly convertible to lhs , which implies
  • both lhs and rhs have arithmetic types , in which case lhs may be volatile -qualified or atomic (since C11)
  • both lhs and rhs have pointer to compatible (ignoring qualifiers) types, or one of the pointers is a pointer to void, and the conversion would not add qualifiers to the pointed-to type. lhs may be volatile or restrict (since C99) -qualified or atomic (since C11) .
  • lhs is a (possibly qualified or atomic (since C11) ) pointer and rhs is a null pointer constant such as NULL or a nullptr_t value (since C23)

[ edit ] Notes

If rhs and lhs overlap in memory (e.g. they are members of the same union), the behavior is undefined unless the overlap is exact and the types are compatible .

Although arrays are not assignable, an array wrapped in a struct is assignable to another object of the same (or compatible) struct type.

The side effect of updating lhs is sequenced after the value computations, but not the side effects of lhs and rhs themselves and the evaluations of the operands are, as usual, unsequenced relative to each other (so the expressions such as i = ++ i ; are undefined)

Assignment strips extra range and precision from floating-point expressions (see FLT_EVAL_METHOD ).

In C++, assignment operators are lvalue expressions, not so in C.

[ edit ] Compound assignment

The compound assignment operator expressions have the form

The expression lhs @= rhs is exactly the same as lhs = lhs @ ( rhs ) , except that lhs is evaluated only once.

[ edit ] References

  • C17 standard (ISO/IEC 9899:2018):
  • 6.5.16 Assignment operators (p: 72-73)
  • C11 standard (ISO/IEC 9899:2011):
  • 6.5.16 Assignment operators (p: 101-104)
  • C99 standard (ISO/IEC 9899:1999):
  • 6.5.16 Assignment operators (p: 91-93)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • 3.3.16 Assignment operators

[ edit ] See Also

Operator precedence

[ edit ] See also

  • 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 19 August 2022, at 08:36.
  • This page has been accessed 53,361 times.
  • Privacy policy
  • About cppreference.com
  • Disclaimers

Powered by MediaWiki

Learn Python practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn python interactively, python introduction.

  • Getting Started
  • Keywords and Identifier
  • Python Comments
  • Python Variables
  • Python Data Types
  • Python Type Conversion
  • Python I/O and Import

Python Operators

  • Python Namespace

Python Flow Control

  • Python if...else
  • Python for Loop
  • Python while Loop
  • Python break and continue
  • Python Pass

Python Functions

  • Python Function
  • Function Argument
  • Python Recursion
  • Anonymous Function
  • Global, Local and Nonlocal
  • Python Global Keyword
  • Python Modules
  • Python Package

Python Datatypes

  • Python Numbers
  • Python List
  • Python Tuple
  • Python String
  • Python Dictionary

Python Files

  • Python File Operation
  • Python Directory
  • Python Exception
  • Exception Handling
  • User-defined Exception

Python Object & Class

  • Classes & Objects
  • Python Inheritance
  • Multiple Inheritance
  • Operator Overloading

Python Advanced Topics

  • Python Iterator
  • Python Generator
  • Python Closure
  • Python Decorators
  • Python Property
  • Python RegEx
  • Python Examples

Python Date and time

  • Python datetime Module
  • Python datetime.strftime()
  • Python datetime.strptime()
  • Current date & time
  • Get current time
  • Timestamp to datetime
  • Python time Module
  • Python time.sleep()

Python Tutorials

Python Operator Overloading

Precedence and Associativity of Operators in Python

Python any()

Python Strings

  • List of Keywords in Python
  • Python all()

Operators are special symbols that perform operations on variables and values. For example,

Here, + is an operator that adds two numbers: 5 and 6 .

Learn Python with Challenges

Solve challenges and become a Python expert.

  • Types of Python Operators

Here's a list of different types of Python operators that we will learn in this tutorial.

  • Arithmetic operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
  • Special Operators

1. Python Arithmetic Operators

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc. For example,

Here, - is an arithmetic operator that subtracts two values or variables.

Example 1: Arithmetic Operators in Python

In the above example, we have used multiple arithmetic operators,

  • + to add a and b
  • - to subtract b from a
  • * to multiply a and b
  • / to divide a by b
  • // to floor divide a by b
  • % to get the remainder
  • ** to get a to the power b

2. Python Assignment Operators

Assignment operators are used to assign values to variables. For example,

Here, = is an assignment operator that assigns 5 to x .

Here's a list of different assignment operators available in Python.

Example 2: Assignment Operators

Here, we have used the += operator to assign the sum of a and b to a .

Similarly, we can use any other assignment operators according to the need.

3. Python Comparison Operators

Comparison operators compare two values/variables and return a boolean result: True or False . For example,

Here, the > comparison operator is used to compare whether a is greater than b or not.

Example 3: Comparison Operators

Note: Comparison operators are used in decision-making and loops. We'll discuss more of the comparison operator and decision-making in later tutorials.

4. Python Logical Operators

Logical operators are used to check whether an expression is True or False . They are used in decision-making. For example,

Here, and is the logical operator AND . Since both a > 2 and b >= 6 are True , the result is True .

Example 4: Logical Operators

Note : Here is the truth table for these logical operators.

5. Python Bitwise operators

Bitwise operators act on operands as if they were strings of binary digits. They operate bit by bit, hence the name.

For example, 2 is 10 in binary and 7 is 111 .

In the table below: Let x = 10 ( 0000 1010 in binary) and y = 4 ( 0000 0100 in binary)

6. Python Special operators

Python language offers some special types of operators like the identity operator and the membership operator. They are described below with examples.

  • Identity operators

In Python, is and is not are used to check if two values are located on the same part of the memory. Two variables that are equal does not imply that they are identical.

Example 4: Identity operators in Python

Here, we see that x1 and y1 are integers of the same values, so they are equal as well as identical. Same is the case with x2 and y2 (strings).

But x3 and y3 are lists. They are equal but not identical. It is because the interpreter locates them separately in memory although they are equal.

  • Membership operators

In Python, in and not in are the membership operators. They are used to test whether a value or variable is found in a sequence ( string , list , tuple , set and dictionary ).

In a dictionary we can only test for presence of key, not the value.

Example 5: Membership operators in Python

Here, 'H' is in x but 'hello' is not present in x (remember, Python is case sensitive).

Similarly, 1 is key and 'a' is the value in dictionary y . Hence, 'a' in y returns False .

Table of Contents

  • Introduction
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python Bitwise operators
  • Python Special operators

Video: Operators in Python

Sorry about that.

Related Tutorials

Python Tutorial

Python Library

Assignment Operators in C

C++ Course: Learn the Essentials

Operators are a fundamental part of all the computations that computers perform. Today we will learn about one of them known as Assignment Operators in C. Assignment Operators are used to assign values to variables. The most common assignment operator is = . Assignment Operators are Binary Operators.

Types of Assignment Operators in C

LHS and RHS Operands

Here is a list of the assignment operators that you can find in the C language:

  • basic assignment ( = )
  • subtraction assignment ( -= )
  • addition assignment ( += )
  • division assignment ( /= )
  • multiplication assignment ( *= )
  • modulo assignment ( %= )
  • bitwise XOR assignment ( ^= )
  • bitwise OR assignment ( |= )
  • bitwise AND assignment ( &= )
  • bitwise right shift assignment ( >>= )
  • bitwise left shift assignment ( <<= )

Working of Assignment Operators in C

This is the complete list of all assignment operators in C. To read the meaning of operator please keep in mind the above example.

Example for Assignment Operators in C

Basic assignment ( = ) :

Subtraction assignment ( -= ) :

Addition assignment ( += ) :

Division assignment ( /= ) :

Multiplication assignment ( *= ) :

Modulo assignment ( %= ) :

Bitwise XOR assignment ( ^= ) :

Bitwise OR assignment ( |= ) :

Bitwise AND assignment ( &= ) :

Bitwise right shift assignment ( >>= ) :

Bitwise left shift assignment ( <<= ) :

This is the detailed explanation of all the assignment operators in C that we have. Hopefully, This is clear to you.

Practice Problems on Assignment Operators in C

1. what will be the value of a after the following code is executed.

A) 10 B) 11 C) 12 D) 15

Answer – C. 12 Explanation: a starts at 10, increases by 5 to 15, then decreases by 3 to 12. So, a is 12.

2. After executing the following code, what is the value of num ?

A) 4 B) 8 C) 16 D) 32

Answer: C) 16 Explanation: After right-shifting 8 (binary 1000) by one and then left-shifting the result by two, the value becomes 16 (binary 10000).

Q. How does the /= operator function? Is it a combination of two other operators?

A. The /= operator is a compound assignment operator in C++. It divides the left operand by the right operand and assigns the result to the left operand. It is equivalent to using the / operator and then the = operator separately.

Q. What is the most basic operator among all the assignment operators available in the C language?

A. The most basic assignment operator in the C language is the simple = operator, which is used for assigning a value to a variable.

  • Assignment operators are used to assign the result of an expression to a variable.
  • There are two types of assignment operators in C. Simple assignment operator and compound assignment operator.
  • Compound Assignment operators are easy to use and the left operand of expression needs not to write again and again.
  • They work the same way in C++ as in C.

CProgramming Tutorial

  • C Programming Tutorial
  • C - Overview
  • C - Environment Setup
  • C - Program Structure
  • C - Basic Syntax
  • C - Data Types
  • C - Variables
  • C - Constants
  • C - Storage Classes
  • C - Operators
  • C - Decision Making
  • C - Functions
  • C - Scope Rules
  • C - Pointers
  • C - Strings
  • C - Structures
  • C - Bit Fields
  • C - Typedef
  • C - Input & Output
  • C - File I/O
  • C - Preprocessors
  • C - Header Files
  • C - Type Casting
  • C - Error Handling
  • C - Recursion
  • C - Variable Arguments
  • C - Memory Management
  • C - Command Line Arguments
  • C Programming useful Resources
  • C - Questions & Answers
  • C - Quick Guide
  • 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

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

Try the following example to understand all the assignment operators available in C −

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

Get certified by completing the course

CsTutorialPoint - Computer Science Tutorials For Beginners

Assignment Operators In C [ Full Information With Examples ]

Assignment Operators In C

Assignment Operators In C

Assignment operators is a binary operator which is used to assign values in a variable , with its right and left sides being a one-one operand. The operand on the left side is variable in which the value is assigned and the right side operands can contain any of the constant, variable, and expression.

The Assignment operator is a lower priority operator. its priority has much lower than the rest of the other operators. Its priority is more than just the comma operator. The priority of all other operators is more than the assignment operator.

We can assign the same value to multiple variables simultaneously by the assignment operator.

x = y = z = 100

Here x, y, and z are initialized to 100.

In C language, the assignment operator can be divided into two categories.

  • Simple assignment operator
  • Compound assignment operators

1. Simple Assignment Operator In C

This operator is used to assign left-side values ​​to the right-side operands, simple assignment operators are represented by (=).

2. Compound Assignment Operators In C

Compound Assignment Operators use the old value of a variable to calculate its new value and reassign the value obtained from the calculation to the same variable.

Examples of compound assignment operators are: (Example: + =, – =, * =, / =,% =, & =, ^ =)

Look at these two statements:

Here in this example, adding 5 to the x variable in the second statement is again being assigned to the x variable.

Compound Assignment Operators provide us with the C language to perform such operation even more effecient and in less time.

Syntax of Compound Assignment Operators

Here op can be any arithmetic operators (+, -, *, /,%).

The above statement is equivalent to the following depending on the function:

Let us now know about some important compound assignment operators one by one.

“+ =” -: This operator adds the right operand to the left operand and assigns the output to the left operand.

“- =” -: This operator subtracts the right operand from the left operand and returns the result to the left operand.

“* =” -: This operator multiplies the right operand with the left operand and assigns the result to the left operand.

“/ =” -: This operator splits the left operand with the right operand and assigns the result to the left operand.

“% =” -: This operator takes the modulus using two operands and assigns the result to the left operand.

There are many other assignment operators such as left shift and (<< =) operator, right shift and operator (>> =), bitwise and assignment operator (& =), bitwise OR assignment operator (^ =)

List of Assignment Operators In C

Read More -:

  • What is Operators In C
  • Relational Operators In C
  • Logical Operators In C
  • Bitwise Operators In C
  • Arithmetic Operators In C
  • Conditional Operator in C
  • Download C Language Notes Pdf
  • C Language Tutorial For Beginners
  • C Programming Examples With Output
  • 250+ C Programs for Practice PDF Free Download

Friends, I hope you have found the answer of your question and you will not have to search about the Assignment operators in C Language 

However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts.

If you want a complete tutorial of C language, then see here  C Language Tutorial . Here you will get all the topics of C Programming Tutorial step by step.

Friends, if you liked this post, then definitely share this post with your friends so that they can get information about the Assignment operators in C Language 

To get the information related to Programming Language, Coding, C, C ++, subscribe to our website newsletter. So that you will get information about our upcoming new posts soon.

' src=

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Advanced JavaScript Operators – Nullish Coalescing, Optional Chaining, and Destructuring Assignment

Hi Everyone! In this article, I'm going to teach you how to use three advanced JavaScript operators: the Nullish Coalescing, Optional Chaining, and Destructuring Assignment operators.

These three operators will help you write clearer and less error-prone code.

The Nullish Coalescing Operator

When you’re inspecting JavaScript code, you may find an expression using a double question mark ( ?? ), as in the code below:

The double question mark is a logical operator that returns the expression on the right-hand side of the mark when the expression on the left-hand side is null or undefined

This operator is also known as the nullish coalescing operator. It’s a new feature introduced in JavaScript ES2020 that allows you to check for null or undefined values in a more concise way.

Nullish Coalescing Operator Syntax

The syntax for the nullish coalescing operator is very simple. It consists of two question marks ?? placed between two operands.

Here’s an example:

The code above assigns the firstName variable value as the value of the username variable.

When the firstName value is null or undefined , then the value Guest will be assigned to the username variable instead:

nullish-coalescing-output

You can also write it this way:

As you can see, you don’t need an if-else statement to check for null or undefined values.

Why JavaScript Needs This Operator

The nullish coalescing operator was created as an improved alternative to the OR operator || .

The OR operator was originally created to provide a default or fallback value when the left-hand expression is falsy, or evaluates to false .

But after some real-world uses, it’s clear that there are times when developers want to return values that are considered falsy, such as 0 and an empty string ( "" )

The use of the OR operator will prevent you from returning any falsy values at all. Consider the following example:

By using the nullish coalescing operator, you will only replace exactly null and undefined values with the right-hand value.

The nullish coalescing operator can be used with any type of value, including numbers, strings, and objects.

Nullish Coalescing Operator Use Cases

The nullish coalescing operator is useful in a variety of situations where you need to check for null or undefined values and provide a default value.

Here are several examples of common use cases:

Handling Missing Function Arguments

When a function is called, it’s possible that some of the arguments may be omitted.

The Nullish Coalescing Operator can be used to provide default values for a missing argument as follows:

Accessing Object Properties

When working with objects, it’s possible that a property may not exist or is undefined .

The Nullish Coalescing Operator can be used to safely access object properties and provide a default value when the property is missing:

Choosing Between a Variable and a Constant

You may want to select a value from a variable or a constant if the variable is null or undefined :

As you can see, the Nullish Coalescing Operator is a great feature that can make your code more concise and reliable.

Using ?? with the || and && Operators

For safety reasons, the double question mark can’t be used together with JavaScript OR ( || ) and AND ( && ) operators without parentheses () separating the operators.

For example, the following code tries to see if either firstName or lastName variable can be used as the value of username before using "Guest" as its value:

This is because JavaScript won’t be able to determine which operator it needs to evaluate first. You need to use parentheses to clearly indicate the priority of the evaluations.

The following code will first evaluate the expressions inside the parentheses:

And that’s how you combine the nullish coalescing operator with either AND or OR operator.

The Optional Chaining Operator

Like the nullish coalescing operator, the optional chaining operator is a modern addition to JavaScript that offers a better way to do things.

The optional chaining operator ?. gives you a safe way to access properties and methods of an object, avoiding an error in the process.

One of the most common problems in JavaScript is that you can get an error when you access a property of an undefined value.

For example, suppose you have a car object as follows:

In the example above, accessing the manufacturer property returns undefined , but when you try to access the address property of the manufacturer property, JavaScript returns an error.

Even though this is how JavaScript works, a better way to handle the non-existent property would be to just return an undefined back, just like when we try to access the manufacturer property.

This is why the optional chaining operator was created. The operator returns either the value of the property, or undefined when the property is null or undefined .

To use the operator, just add a question mark in front of the dot . notation:

The optional chaining operator can be added anytime you use the dot notation to access a property or method.

This operator allows you to avoid the TypeError that occurs when accessing a property or calling a method from a non-existent property:

Note that the optional chaining operator only checks the value before it. If the car variable can be null , then you need to add the operator after when accessing the car object as well.

See the following example:

And that’s how the optional chaining operator works. It’s really useful when you’re working with objects in your project.

Next, let’s learn about the destructuring assignment.

Destructuring Assignment Operator

The destructuring assignment is a special operator that allows you to "unpack" or "extract" the values of JavaScript arrays and objects. It has become one of the most useful features of JavaScript language for two reasons:

  • It helps you to avoid code repetition.
  • It keeps your code clean and easy to understand.

Let’s see how you can destructure an array and an object next.

Destructuring Arrays

Here’s how you normally assign an array values to variables:

The code above works, but you need two lines of code to get two elements from an array. Using the destructuring assignment, you can assign array elements into variables in one short line:

The above code will return the same value for firstIndex and secondIndex variable. No matter how many elements you have, the destructuring will start from the zero index.

To create a destructuring assignment, you need to add square brackets [] after the let / const keyword. When you add square brackets after the assignment ( = ) operator, it’s an array. If you add them before the assignment operator, it’s a destructuring assignment.

You can also use the rest operator …​ to copy the rest of the values after your assignment. Take a look at the following example:

The rest variable will contain an array with values of ['Jack','Aston'] .

You can also put default values for these variables when the extracted value is undefined:

You can also immediately assign the return of a function into assignments. This is frequently used in libraries like React:

The variable a will return "John" and b will return "Jack".

Finally, you can also ignore some variables by skipping the assignment for that index:

Destructuring assignment makes unpacking array values easier and shorter, with less repetition.

Object Destructuring

Just like arrays, you can destructure objects the same way, but instead of using the square brackets ( [] ) you need to use the curly brackets ( {} ):

You can use the colon delimiter ( : ) to assign the property into a different name. The example below assign the value of firstName into name :

Note that you still only create two variables: name and lastName . The firstName is assigned to name , so it won’t create a separate variable.

Just like arrays, you can destructure an object returned by a function immediately:

Also, you can destructure an object from the function parameters, exactly when you define the function:

The destructuring assignment is a useful addition to JavaScript that makes it easier to unpack values from objects and arrays. You’re going to use it frequently when you code using a library like React.

JavaScript is constantly improving every year, and the three operators explained in this article are a great addition that can help you produce more concise and readable code.

If you enjoyed this article and want to take your JavaScript skills to the next level, I recommend you check out my new book Beginning Modern JavaScript here .

beginning-js-cover

The book is designed to be easy to understand and accessible to anyone looking to learn JavaScript. It provides a step-by-step gentle guide that will help you understand how to use JavaScript to create a dynamic application.

Here's my promise: You will actually feel like you understand what you're doing with JavaScript.

Until next time!

JavaScript Full Stack Developer currently working with fullstack JS using React and Express. Nathan loves to write about his experience in programming to help other people.

If you read this far, thank the author to show them you care. Say Thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

  • BYJU'S GATE
  • GATE Study Material
  • GATE Notes For CSE
  • Introduction To C Programming
  • Operators In C

Assignment Operators in C

We use this type of operator to transform as well as assign the values to any variable in an operation. In any given assignment operator, the right side is a value, and the left side is a variable. The value present on the right side of the operator must have the same data type as that of the variable present on the left side. In any other case, the compiler raises an error.

In this article, we will take a look into the Assignment Operators in C according to the GATE Syllabus for CSE (Computer Science Engineering) . Read ahead to know more.

Table of Contents

  • Working Of Assignment Operators In C
  • Example Of Assignment Operators In C
  • Practice Problems On Assignment Operators In C

Types of Assignment Operators in C

An assignment operator is basically a binary operator that helps in modifying the variable to its left with the use of the value to its right. We utilize the assignment operators to transform and assign values to any variables.

Here is a list of the assignment operators that you can find in the C language:

  • basic assignment ( = )
  • subtraction assignment ( -= )
  • addition assignment ( += )
  • division assignment ( /= )
  • multiplication assignment ( *= )
  • modulo assignment ( %= )
  • bitwise XOR assignment ( ^= )
  • bitwise OR assignment ( |= )
  • bitwise AND assignment ( &= )
  • bitwise right shift assignment ( >>= )
  • bitwise left shift assignment ( <<= )

Working of Assignment Operators in C

Here is a table that discusses, in brief, all the Assignment operators that the C language supports:

Example of Assignment Operators in C

Let us look at an example to understand how these work in a code:

#include <stdio.h>

int x = 21;

printf(“Line A – = Example of the Value of y = %d\n”, y );

printf(“Line B – -= Example of the Value of y = %d\n”, y );

printf(“Line C – += Example of the Value of c = %d\n”, c );

printf(“Line D – /= Example of the Value of y = %d\n”, y );

printf(“Line E – *= Example of the Value of y = %d\n”, y );

y <<= 2;

printf(“Line F – <<= Example of the Value of y = %d\n”, y );

printf(“Line G – %= Example of the Value of y = %d\n”, y );

y &= 2;

printf(“Line H – &= Example of the Value of y = %d\n”, y );

y >>= 2;

printf(“Line I – >>= Example of the Value of y = %d\n”, y );

printf(“Line J – |= Example of the Value of y = %d\n”, y );

printf(“Line K – ^= Example of the Value of y = %d\n”, y );

The compilation and execution of the program mentioned above will produce a result as follows:

Line A – = Example of the Value of y = 21

Line B – -= Example of the Value of y = 21

Line C – += Example of the Value of y = 42

Line D – /= Example of the Value of y = 21

Line E – *= Example of the Value of y = 441

Line F – <<= Example of the Value of y = 44

Line G – %= Example of the Value of y = 11

Line H – &= Example of the Value of y = 2

Line I – >>= Example of the Value of y = 11

Line J – |= Example of the Value of y = 2

Line K – ^= Example of the Value of y = 0

Here is another example of how the assignment operators work in the C language:

int y = 10;

printf(“z = x + y = %d \n”,z);

printf(“z += x = %d \n”,z);

printf(“z -= x = %d \n”,z);

printf(“z *= x = %d \n”,z);

printf(“z /= x = %d \n”,z);

printf(“z %= x = %d \n”,z);

c &= x ;

printf(“c &= x = %d \n”,z);

printf(“z ^= x = %d \n”,z);

printf(“z |= x = %d \n”,z);

z <<= 2 ;

printf(“z <<= 2 = %d \n”,z);

z >>= 2 ;

printf(“z >>= 2 = %d \n”,z);

The output generated here will be:

z = x + y = 15

z += x = 20

z -= x = 15

z *= x = 75

z &= x = 0

z ^= x = 10

z |= x = 10

z <<= 2 = 40

z >>= 2 = 10

z >>= 2 = 2

Practice Problems on Assignment Operators in C

1. What would be the output obtained from the program given below?

#include<stdio.h>

p += p += p += 3;

printf(“%d”,p);

Answer – A. 20

p+=p+=p+=3; it can written as p+=p+=p=p+3; p=2; Or, p+=p+=5; p=5; Or, p+=p=5+5; p=5; Or, p+=10; p=10; Or, p=p+10; p=10; Or, p=20. So, finally p=20.

2. Which of these is an invalid type of assignment operator?

D. None of these

Answer – D. None of these

All of these are valid types of assignment operators.

How does the /= operator work? Is it a combination of two other operators?

Yes, the /+ operator is a combination of the = and / operators. The / operator divides the current value of the available variable first on the left using the available value on the right. It then assigns the obtained result to the available variable on the left side.

What is the most basic operator among all the assignment operators available in the C language?

The = operator is the most basic one used in the C language. We use this operator to assign the value available in the right to the value mentioned on the left side of the operator.

Keep learning and stay tuned to get the latest updates on  GATE Exam  along with  GATE Eligibility Criteria ,  GATE 2023 ,  GATE Admit Card ,  GATE Syllabus for CSE (Computer Science Engineering) ,  GATE CSE Notes ,  GATE CSE Question Paper , and more.

Also Explore,

  • Arithmetic Operators in C
  • Bitwise Operators in C
  • Increment and Decrement Operators in C
  • Logical Operators in C
  • Operators in C
  • Relational Operators in C

Leave a Comment Cancel reply

Your Mobile number and Email id will not be published. Required fields are marked *

Request OTP on Voice Call

Post My Comment

assignment operator x

GATE 2024 - Your dream can come true!

Download the ultimate guide to gate preparation.

  • Share Share

Register with BYJU'S & Download Free PDFs

Register with byju's & watch live videos.

Download the Unstop app now!

Check out the latest opportunities just for you!

Assignment Operators In C | A Complete Guide With Detailed Examples

Shivani Goyal

Table of content: 

What are assignment operators in c, how do assignment operators in c language work step-by-step explanation, types/ classification of assignment operators in c, bitwise assignment operators in c, table of assignment operators in c, relational vs. assignment relational operators in c, frequently asked questions.

Operators in C programming language are symbols or special characters that perform specific operations on one or more operands. They enable various computations and manipulation of data/ operands in C programs . These operands can be variables, constants, or expressions. It is important to understand the concept of various types of operators to utilize them effectively in writing efficient and expressive C code. In this article, we will focus on assignment operators in C .

Other types of operators include arithmetic , bitwise, logical , relational, ternary/ conditional, etc. Collectively, they enable complex computations, comparisons, and control flow within programs, allowing developers to manipulate data in a variety of ways.

Conditional/ If-Else Statements In C | The Ultimate Guide

Assignment operators are used to assign values to variables. In other words, they are used to update the value of a variable with a new value based on a certain operation or calculation. The most commonly used assignment operator is the equal-to operator (=), which assigns the right-hand side value to the variable on the left-hand side of the operator.

For example, the expression x = 5 assigns the value of 5 to the variable x.

Other assignment operators in C include addition assignment (+=), subtraction assignment (-=), multiplication assignment (*=), division assignment (/=), and modulus/ modulo assignment (%=). As their name suggests, they are used to assign the resultant value of addition, subtraction, multiplication, division, and modulus operations (respectively) to the left-side variable/ operand.

For example, the equation x += 5 is equivalent to x = x + 5. It updates the value of x by adding 5 to its current value.

These assignment operators can be combined with other operators to perform more complex operations in a single statement. For example, "x += y * 3" updates the value of x by adding three times the value of y to its current value.

Using basic assignment operators can help to make code more concise and easier to read, as well as improve performance by reducing the number of operations required. However, it is important to use them carefully and avoid unintended consequences such as unintended side effects or errors.

variable_name operator expression;

Here, 

  • The variable_name refers to the name of the variable whose value you are assigning or updating. 
  • The term operator refers to the respective assignment operator you are using.
  • And, expression is the right-hand operand, i.e., it refers to the value you are assigning to the variable. 

Here are some examples of assignment operators and their syntax:

x = 5; // assigns the value of 5 to the variable x y += 10; // adds 10 to the current value of y and updates y with the result z *= 3; // multiplies the current value of z by 3 and updates z with the result

As mentioned before, we use the various assignment operators in C to initialize or update the values of variables in a program. In this section, we will discuss the working mechanism behind these operators.  

  • Step 1 (The variable): The first step is to select the variable that we want to assign a value to. This variable can be of any data type , such as integer, float, or char.
  • Step 2 (The operator):  The second step is to select the assignment operator that we want to use. In C language, the most commonly used assignment operator is the simple assignment operator "=", which assigns the value on the right side operand to the variable on the left side operand.
  • Step 3 (The value or expression): The third step is to provide the value or expression that we want to assign to the variable. This value or expression can be a constant , a variable , or an expression that combines variables and constants using arithmetic or logical operators.
  • Step 4 (The evaluation):  Once we have selected the variable, the operator, and the value or expression, the computer evaluates the expression on the right-hand side of the operator. This evaluation involves performing any necessary arithmetic or logical operations based on the precedence rules of the operators.
  • Step 5 (The assignment): Finally, the computer assigns the evaluated value or expression to the variable on the left-hand side of the assignment operator. This assignment replaces the previous value of the variable with the new value.

Assignment Operator Example:

The initial values of x and y are: 5, 10 The updated value of x is: 15

Code Explanation:

We begin the sample C program above by including the <stdio.h> header file and initiate the main() function. Inside the main()-

  • First, we declare two integer variables , x and y, and assign the values of 5 to x and 10 to y.
  • We print the initial values of these variables to the console using the printf() function .
  • Next, we use the addition assignment operator (as mentioned in the code comments ) to add the initial value of y to the initial value of x and assign the result to x.
  • The operation involves adding the value of y, which is 5, to the value of x, which is 10. The output is, hence, 15.
  • Once again, we use the printf() function to display the updated value of x.

12 Ways To Compare Strings In Python Explained (With Examples)

All the assignment operators in the C programming language can be classified into two major types with subtypes. These types and the operators included in them are mentioned below-

Simple Assignment Operator In C

There is only one assignment operator which comes under this category. Yes, we are talking about the basic equal-to/ assignment operator, represented by the symbol (=). As mentioned before, it is used to assign a value to a variable. It assigns the value on the right-hand side of the operator to the variable on the left-hand side/ left operand.

It will be easier to understand why we call this operator simple when you check out the other category, i.e., compound operators. 

Compound Assignment Operators In C

The compound assignment operators are called as such because they combine a binary operation with the assignment operation. That is, these operators perform a binary operation on the values of the variable and the value on the right-hand side and then assign the result to the variable on the left-hand side/ left operand.

There are several types of compound assignment operator expressions in C:

  • Subtraction Assignment Operator (-=)
  • Addition Assignment Operator (+=)
  • Multiplication Assignment Operator (=)
  • Division Assignment Operator (/=)
  • Modulus Assignment Operator (%=)

The advantage of using these operators is that they provide a shorthand notation for performing common operations such as addition, multiplication, division, etc. 

Table of assignment operators in C, their symbols and short examples.

Now, we will explore each of the assignment operator types mentioned above in detail. 

Simple Assignment Operator In C (=)

The simple assignment operator assigns the value on the right to the variable on the left. It is the most commonly used assignment operator in C language and other languages as well. Below is an example of how to use simple assignment operator expressions.

Sample Code :

The value of x is 5
  • We begin the code by including the standard input-output header file, <stdio.h>, which provides necessary functions for input and output operations in C programming.
  • Next, the main() function serves as the entry point for program execution. 
  • Inside main (), we declare an integer variable named x and initialize it with the value 5 using the simple assignment operator .
  • This step reserves a memory location to store an integer value and assigns the value 5 to x.
  • Next, we use the printf() function to display the output. We also use a formatted string to specify the desired output format and insert the value of x using the %d format specifier .
  • Finally, the program successfully completes execution with the return 0 statement. It indicates the successful termination of the main() function and the program as a whole.

Addition Assignment Operator In C (+=)

The addition assignment operator adds the value given on its right side to the current value of the variable on the left. And then assigns the result to the variable on the left. Alternatively, it can also add the initial value of the first variable to the initial value of a second variable and assign it back to the first variable.

The value of x is 8

Code Explanation :

The C program above begins with the inclusion of the input/ output header file.

  • Inside the main() function , we declare an integer variable, x , and initialize it with the value 5 using the simple assignment operator. 
  • Next, we use the addition assignment operator (+=) to add a value to the variable on the left side, i.e., x, and assign the result back to it.
  • Here, we add a value of 3 to x's initial value and reassing it back. That is, x += 3 is equivalent to x = x + 3, which adds 3 to the value of x and stores the result back into x.
  • Then, we use the printf() function to display the output. Inside this, we use a formatted string with the %d specifier as the placeholder for the value of x.
  • Finally, the program terminates with the return 0 statement.

Subtraction Assignment Operator In C (-=)

The subtraction assignment operator is used to subtract a given value, mentioned on the right side of the operator, from the initial value of the variable on the left (i.e., the left operand). And then assgin the result back to the original variable on the left. Alternatively, we can also subtract the value of a second variable from the initial variable.

Sample Code:

The value of x is 7

Inside the main() function of the example above, we-

  • First, declare an integer variable x and assign the value 10 to it using the simple operator.
  • We then use the subtraction assignment operator (-=) to subtract a value of 3 from the initial value of x. The result is assigned back to x using this operator. 
  • That is, the expression x -= 3 is equivalent to x = x - 3, which means we subtract 3 from 5 (i.e., the value of x) and update the value of x with the result.
  • We then display the updated value of the variable x to the console using the printf() function . In that, we use a formatted string to display a message and use the %d specifier as a placeholder for x.

Multiplication Assignment Operator In C (*=)

The multiplication assignment operator (*=) first multiplies the given value (on the right) with the initial/ current value of the variable on the left (left operand). And then assigns the result back to the variable on the left. Alternatively, it can also be used to multiply the initial value of a variable by the value of another variable in the program. 

The value of x is 20
  • We begin the main() function in the example above after including the <stdio.h> file. 
  • Inside main(), we declare an integer variable named x and initialize it with the value 5 using the simple assignment operator.
  • Next, we show how to use the multiplication assignment operator by using it to multiply the initial value of x by 4 and then assigning the result back to variable x.
  • That is, the expression x *= 4 implies x = x * 4, which multiplies the value of x by 4 and stores the result back into x.
  • Using the printf() function , we then display the updated value of x along with a message. This message results from a formatted string where the placeholder for x is the %d format specifier.

Division Assignment Operator In C(/=)

The division assignment operator (/=) first divides the current/ initial value of the variable mentioned on its left side by the value given on its right. Then, the revised value/ result is assigned back to the variable on the left. Alternatively, we can also use this operator to divide the value of one variable by another variable and then update the value of one. 

  • In the main() function of the example, we first declare an integer variable called x and then use the simple assignment operator to initialize it with the value 10. 
  • Next, we use the division assignment operator to divide the value of x by 2 and assign x with the resultant value of this operation. 
  • That is, here, the expression x /= 2 can be expanded as x = x / 2, which ultimately divides the value of x by 2 and stores the result back into x.
  • The output is displayed on the console using the printf() function . We also use formatted string and the %d format specifier in the print function to display the result with a message.

Modulo Assignment Operator In C (%=)

The modulo assignment operator (%=) begins by dividing the value of its left-side operand by the right-side operand. That is, it divides the initial value of the variable on the left by the value on the right. And then, it assigns the resulting remainder, back to the variable on the left. Note that the value on the right can also be the value of another variable in the program. 

The value of x is 3
  • We include the <stdio.h> file and then define the main() function , which serves as the entry point of this program. 
  • Inside main(), we declare a variable, x, of integer data type and initialize it with the value of 14. 
  • After that, we use the modulo assignment operator ( %=) to calculate the remainder from the division of the variable on the left side by a specified value and assign the result back to that variable.
  • In this example, we divide the value of x by 4 and reassign the remainder to it.
  • That is, x %= 4 is equivalent to x = x % 4, which ultimately calculates the remainder when x is divided by 4 and stores the result back into x.
  • This reassigned/ updated value of x is displayed on the console using the printf() function with a formatted string and %d format specifier. 

Check this out-  Boosting Career Opportunities For Engineers Through E-School Competitions

We have already discussed the most commonly used assignment operators. But there are a few other compound assignment operators that you must know about. These are the bitwise assignment operators, which first conduct the respective bitwise operation on the operands and then assign the result back to the left operand in the expression.

There are three types of bitwise assignment operators in C, which we have discussed ahead. 

Bitwise AND Assignment Operator In C (&=)

The bitwise AND assignment operator (&=) performs a bitwise AND operation between the current value of the variable on the left (i.e., the left operand) and the value on the right (i.e., the right operand) and then assigns the result to the variable on the left. The value on the right can also be another variable.

The value of x is 4

In the example C program above, we define the main() function (which serves as the entry point) after including the <stdio.h> file.

  • We then declare an integer variable called  x and use the basic assignment operator to initialize it with the value 12. 
  • Next, we use the  bitwise AND assignment operator (&=) to perform a bitwise AND operation between the value of the variable on the left side and a specified value and then assign the result back to that variable.
  • That is, the equation x &= 5 , which actually implies x = x & 5, performs a bitwise AND between the value of x and 5 and stores the result back into x.
  • We display the result of this operation to the console with the printf() function , a formatted string, and the %d specifier.

Bitwise OR Assignment Operator In C (|=)

The bitwise OR assignment operator (|=) performs a bitwise OR operation between the current value of the variable on the left and the value on the right and then assigns the result to the variable on the left.

Code Example:

The value of x is 13

In the example above-

  • We first include the standard input/ output file in C and then initiate the main() function .
  • Then, we declare an integer variable x, and initialize it with the value 12. This reserves a memory location to store an integer value.
  • Next, using the bitwise OR assignment operator , we perform a bitwise OR operation between the value of the variable on the left side (i.e., 12) and a specified value (i.e., 5) and assign the result back to the left-side variable, i.e., x.
  • That is, the expression x |= 5 leads to the evaluation of x = x | 5, which performs a bitwise OR between the value of x and 5 and stores the result back into x.
  • Then, we use the printf() function to display the result/ updated value of left operand x to the console. We also use a formatted string and the %d specifier inside printf().

Left Shift Assignment Operator In C (<<=)

The bitwise left shift assignment operator (<<=) first shifts the bits of the current value of the variable on the left (i.e., left-hand operand) by the number of positions specified by the value on the right. And then, assigns the result back to the variable on the left.

The value of x is 40

In this example program, we first include the essential header file and then initiate the main() function .

  • Inside main(), we declare an integer variable x and initialize it with the value 10. This step reserves a memory location to store an integer value and assigns the value 10 to x.
  • Next, we apply the left shift assignment operator (<<=) on this variable to perform a left shift operation on its value by a specified number of bits (here, 2) and assign the result back to that variable.
  • That is, the equation x <<= 2 expands to x = x << 2, which performs a left shift on the value of x by 2 bits and stores the result back into x.
  • We print the new value of the left-hand side variable x to the console using the printf() function . Herein, we also use the formatted string to display a message and use %d as the placeholder for the value of x. 

Right Shift Assignment Operator In C (>>=)

The bitwise right shift assignment operator (>>=) begins by shifting the bits of the initial value of the variable on the left (i.e., left-hand operand) by the number of positions specified by the right-hand value and then assigns the result to the variable on the left.

  • We start this code example by including the standard input-output header file, <stdio.h>, which provides necessary functions for input and output operations. 
  • Then, inside the main() function (which serves as the entry point for program execution), we declare an integer variable x and initialize it with the value 10. 
  • Next, we employ the right shift assignment operator ( >>=) to shift the bits of the value on the left side (i.e., 10, the value of x) by a specified number of positions (i.e., 1) to the right. And then, assign the result back to the left-hand side variable.
  • That is, the equation x >>= 1 is equivalent to x = x >> 1, which performs a right shift operation on the value of x by 1 position and stores the result back into x.
  • We publish this updated value of the variable x to the console using a formatted string and %d specifier inside the printf() function . 

Also read- Identifiers In C | Rules For Definition, Types, And More!

Control Statements In C | The Beginner's Guide (With Examples)

Both the relational and the assignment operators serve different purposes and have distinct characteristics in programming languages like C. Assignment operators deal with assigning values to operands/ variables. In contrast, relational operators focus on making comparisons between operands, thus enabling logical decision-making in program flow control and conditional statements.

Here are some points highlighting the differences between relational and assignment operators in C:

Assignment Operators: Assignment operators are used to assign values or expressions to variables. They perform the task of storing a value in a variable.

Relational Operators: Relational operators are used to compare values or expressions. They determine the relationship between two operands and produce a Boolean result (true or false) based on the comparison.

Assignment Operators: Assignment operators are typically represented by a single character followed by an equal sign, such as (=), (+=), (-=), (*=), etc.

Relational Operators: Relational operators are represented by two or more characters, including equality operators (==, !=), other relational operators (<, >, <=, >=), etc.

Assignment Operators: Assignment operators in C perform the task of assigning a value or expression to a variable. They modify the value of the left-hand side variable based on the right-hand side value or expression.

Relational Operators: Relational operators compare the values of two operands and return a Boolean result indicating whether the comparison is true or false.

Result Type:

Assignment Operators: The result of an assignment operator is not a value in itself but the assignment of value to the variable on the left-hand side of the operator. 

Relational Operators: The result of a relational operator is a Boolean value, either true or false, indicating the outcome of the comparison.

Assignment Operators: Assignment operators in C are primarily used for variable assignments, updating variables, and performing calculations involving the current value of a variable.

Relational Operators: Relational operators are used in conditional statements (if, while, for) and expressions that require comparison between variables or values.

Precedence:

Assignment Operators: Assignment operators in C have lower precedence compared to most other operators, which means they are evaluated after most other operations in an expression.

Relational Operators : Relational operators have higher precedence than assignment operators, allowing them to be evaluated before assignment operations.

Hero Campus Challenge S8 Winners Take Us Through Their Road To Victory

The assignment operator in C is one of the most important and commonly used operators in the language. It is used to assign values to variables, which is essential for writing any program. Compound assignment operators can be used to make code more concise and efficient. All in all, these assignment operators are fundamental operators that allow programmers to store and manipulate data effectively throughout their programs. It is important to understand the different types of assignment operators and how to use them correctly in order to write efficient and effective C code.

Also read-  100+ Top C Interview Questions With Answers (2023)

Q. What is an assignment operator in C?

An assignment operator is a type of operator in the C language that is used to assign a value or expression to a variable. This could be a direct value (as in initialization) or the value that results from a compound operation (like the result of addition, subtraction, multiplication, etc. operations).

The most commonly used assignment operator is the equal sign (=), that is, the basic assignment operator. It assigns the value on the right-hand side to the variable on the left-hand side of the operator. 

Q. What is the difference between a simple assignment operator and a compound assignment operator?

The simple assignment operator, that is, the equal-to operator (=), assigns a single value to a variable. A compound assignment operator(binary operator), on the other hand, performs a binary operation (such as addition, subtraction, multiplication, etc.) between the current value of a variable and another value or expression and then assigns the result to the variable. Its examples are- addition assignment (+=), multiplication assignment (*=), modulo assignment (%=), etc. 

Q. What happens if I use an assignment operator with incompatible types in C?

In the C programming language, using an assignment operator with incompatible types results in a compilation error. C is a statically typed language, which means that variables must be explicitly declared with their data types, and the compiler enforces strict type-checking during the compilation process . If an attempt is made to assign a value of one type to a variable of a different, incompatible type, the compiler will raise an error.

For example, trying to assign a character (A) to an integer variable declared as int will lead to a compilation error in the C program . This mechanism helps catch potential type-related errors early in the development process, ensuring that the program adheres to the specified type rules and preventing unexpected behavior during runtime.

Q. Can I chain multiple assignment operators together in C language?

In the C programming language, it is not possible to chain multiple assignment operators together in a single statement. Each assignment operation in C must be a standalone statement. Unlike some other languages where you can chain assignments like a = b = c = 5, C does not support this kind of chaining.

For example, the following code is not valid in C:

int a, b, c; a = b = c = 5; // This is not allowed in C

To achieve the desired result, you need to perform each assignment separately:

int a, b, c; c = 5; b = c; a = b;

This assigns the value 5 to all three variables (a, b, and c), but each assignment is written as a separate statement.

Q. Are there any precedence rules for assignment operators?

Yes, C has precedence rules for assignment operators. The assignment operator (=) has a lower precedence than most other operators. This means that when an expression contains both assignment and other operators, the assignment will be performed after the evaluation of the other operators.

For example:

int a, b, c; a = b = c = 5 + 3 * 2;

In this example, the multiplication (*) has higher precedence than the assignment (=). So, 3 * 2 is evaluated first, resulting in 6. Then, 5 + 6 is evaluated, resulting in 11. Finally, the assignment is performed from right to left, so c, b, and a will all be assigned the value 11.

It's important to note that associativity also plays a role. The assignment operators in C are right-associative, which means that when multiple assignments appear in a row, they are evaluated from right to left. In the example above, c = 5 + 3 * 2 is evaluated first, followed by b = c, and finally a = b.

Now that you know all about assignment operators in C, check out some other interesting topics:

  • 5 Types Of Literals In C & More Explained With Examples!
  • Tokens In C | A Complete Guide To 7 Token Types (With Examples)
  • Escape Sequence In C | 15 Types Explained With Code Examples
  • Swapping Of Two Numbers In C | 5 Ways Explained (With Examples)
  • Keywords In C Language | Properties, Use, & Detailed Explanation!

Shivani Goyal

I am an economics graduate using my qualifications and life skills to observe & absorb what life has to offer. A strong believer in 'Don't die before you are dead' philosophy, at Unstop I am producing content that resonates and enables you to be #Unstoppable. When I don't have to be presentable for the job, I'd be elbow deep in paint/ pencil residue, immersed in a good read or socializing in the flesh.

Hero Campus Challenge Season 9

to our newsletter

Blogs you need to hog!

Conditional/ If-Else Statements In C | The Ultimate Guide

Conditional/ If-Else Statements In C | The Ultimate Guide

assignment operator x

12 Ways To Compare Strings In Python Explained (With Examples)

Control Statements In C | The Beginner's Guide (With Examples)

Control Statements In C | The Beginner's Guide (With Examples)

From Good to Great: How Essay Writing Services Can Elevate Your Writing Skills

From Good to Great: How Essay Writing Services Can Elevate Your Writing Skills

assignment operator x

share this!

January 7, 2024

This article has been reviewed according to Science X's editorial process and policies . Editors have highlighted the following attributes while ensuring the content's credibility:

fact-checked

reputable news agency

Coal miners in North Dakota unearth a mammoth tusk buried for thousands of years

by Jack Dura

Coal miners in North Dakota unearth a mammoth tusk buried for thousands of years

The first person to spot it was a shovel operator working the overnight shift, eyeing a glint of white as he scooped up a giant mound of dirt and dropped it into a dump truck.

Later, after the truck driver dumped the load, a dozer driver was ready to flatten the dirt but stopped for a closer look when he, too, spotted that bit of white.

Only then did the miners realize they had unearthed something special: a 7-foot-long (2.1 meters) mammoth tusk that had been buried for thousands of years.

"We were very fortunate, lucky to find what we found," said David Straley, an executive of North American Coal, which owns the mine.

The miners unearthed the tusk from an old streambed, about 40 feet (12.1 meters) deep, at the Freedom Mine near Beulah, North Dakota. The 45,000-acre (18,210-hectare) surface mine produces up to 16 million tons (14.5 million metric tons) of lignite coal per year.

After spotting the tusk, the crews stopped digging in the area and called in experts, who estimated it to be 10,000 to 100,000 years old.

Jeff Person, a paleontologist with the North Dakota Geologic Survey, was among those to respond. He expressed surprise that the mammoth tusk hadn't suffered more damage, considering the massive equipment used at the site.

"It's miraculous that it came out pretty much unscathed," Person said.

Coal miners in North Dakota unearth a mammoth tusk buried for thousands of years

A subsequent dig at the discovery site found more bones. Person described it as a "trickle of finds," totaling more than 20 bones, including a shoulder blade, ribs, a tooth and parts of hips, but it's likely to be the most complete mammoth found in North Dakota, where it's much more common to dig up an isolated mammoth bone , tooth or piece of a tusk.

"It's not a lot of bones compared to how many are in the skeleton, but it's enough that we know that this is all associated, and it's a lot more than we've ever found of one animal together, so that's really given us some significance," Person said.

Mammoths once roamed across parts of Africa, Asia, Europe and North America. Specimens have been found throughout the United States and Canada, said Paul Ullmann, a University of North Dakota vertebrate paleontologist.

The mine's discovery is fairly rare in North Dakota and the region, as many remains of animals alive during the last Ice Age were destroyed by glaciations and movements of ice sheets, Ullmann said.

Other areas have yielded more mammonth remains, such as bonebeds of skeletons in Texas and South Dakota. People even have found frozen carcasses in the permafrost of Canada and Siberia, he said.

Mammoths went extinct about 10,000 years ago in what is now North Dakota, according to the Geologic Survey. They were larger than elephants today and were covered in thick wool. Cave paintings dating back 13,000 years depict mammoths.

Ullmann calls mammoths "media superstars almost as much as dinosaurs," citing the "Ice Age" film franchise.

This ivory tusk, weighing more than 50 pounds (22.6 kilograms), is considered fragile. It has been wrapped in plastic as the paleontologists try to control how fast it dehydrates. Too quickly, and the bone could break apart and be destroyed, Person said.

Coal miners in North Dakota unearth a mammoth tusk buried for thousands of years

Other bones also have been wrapped in plastic and placed in drawers. The bones will remain in plastic for at least several months until the scientists can figure how to get the water out safely. The paleontologists will identify the mammoth species later, Person said.

The mining company plans to donate the bones to the state for educational purposes.

"Our goal is to give it to the kids," Straley said.

North Dakota has a landscape primed for bones and fossils, including dinosaurs. Perhaps the best known fossil from the state is that of Dakota, a mummified duckbilled dinosaur with fossilized skin, Ullmann said.

The state's rich fossil record is largely due to the landscape's "low-elevation, lush, ecologically productive environments in the past," Ullmann said.

North Dakota's location adjacent to the Rocky Mountains puts it in the path of eroding sediments and rivers, which have buried animal remains for 80 million years or more, he said.

"It's been a perfect scenario that we have really productive environments with a lot of life, but we also had the perfect scenario, geologically, to bury the remains," Ullmann said.

© 2024 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without permission.

Explore further

Feedback to editors

assignment operator x

Saturday Citations: Honey yields, exercising under the influence, unexpected benefits of hearing aids

21 hours ago

assignment operator x

Inhalable sensors could enable early lung cancer detection

Jan 5, 2024

assignment operator x

Study finds protected areas for elephants work best if they are connected

assignment operator x

Cult mentality: Professor makes monumental discovery in Italy

assignment operator x

Research team combines two catalysts to make common chemical production safer, more environmentally friendly

assignment operator x

Using Berry phase monopole engineering for high-temperature spintronic devices

assignment operator x

A new approach can address antibiotic resistance to Mycobacterium abscessus

assignment operator x

Increase in rice farming in sub-Saharan Africa found to be producing rising amounts of methane

assignment operator x

NASA/JAXA XRISM mission reveals its first look at X-ray cosmos

assignment operator x

Calculating the number of oranges that can be plucked from a fruit stand before it collapses

Relevant physicsforums posts, in praise of pandas.

12 hours ago

A potent antibiotic for a drug-resistant superbug

Jan 3, 2024

How does one check life signs of an insect?

Jan 2, 2024

How a-priori intelligence is even possible?

Jan 1, 2024

An anaerobic denitrification question

What are mesocarnivore/hypocarnivore/omnivore.

Dec 30, 2023

More from Biology and Medical

Related Stories

assignment operator x

Agriculture officials confirm 25th case of cattle anthrax in North Dakota this year

Dec 2, 2023

assignment operator x

'Mammoth central' found at Mexico airport construction site

Sep 4, 2020

assignment operator x

Researchers recover ancient mammoth tusk during deep-sea expedition

Nov 23, 2021

assignment operator x

CT scanner captures entire wooly mammoth tusk

Aug 9, 2022

assignment operator x

US construction crew finds triceratops skeleton in Colorado (Update)

Aug 30, 2017

assignment operator x

Skeleton of huge dinosaur unearthed in Portugal

Aug 29, 2022

Recommended for you

assignment operator x

New evidence that insect wings may have evolved from gills

Jan 4, 2024

assignment operator x

Australian fossil suggests photosynthesis evolved at least 1.75 billion years ago

assignment operator x

Fossil birds: Surfaces of cervical vertebrae show conspicuous tubercles that may have served as 'internal bony armor'

assignment operator x

'Giant' predator worms more than half a billion years old discovered in North Greenland

assignment operator x

New research shows 'juvenile' T. rex fossils are a distinct species of small tyrannosaur

assignment operator x

First in situ documentation of a fossilized megalodon tooth in the deep sea

Dec 21, 2023

Let us know if there is a problem with our content

Use this form if you have come across a typo, inaccuracy or would like to send an edit request for the content on this page. For general inquiries, please use our contact form . For general feedback, use the public comments section below (please adhere to guidelines ).

Please select the most appropriate category to facilitate processing of your request

Thank you for taking time to provide your feedback to the editors.

Your feedback is important to us. However, we do not guarantee individual replies due to the high volume of messages.

E-mail the story

Your email address is used only to let the recipient know who sent the email. Neither your address nor the recipient's address will be used for any other purpose. The information you enter will appear in your e-mail message and is not retained by Phys.org in any form.

Newsletter sign up

Get weekly and/or daily updates delivered to your inbox. You can unsubscribe at any time and we'll never share your details to third parties.

More information Privacy policy

Donate and enjoy an ad-free experience

We keep our content available to everyone. Consider supporting Science X's mission by getting a premium account.

E-mail newsletter

  • 90% Refund @Courses
  • Free Python 3 Tutorial
  • Control Flow
  • Exception Handling
  • Python Programs
  • Python Projects
  • Python Interview Questions
  • Python Database
  • Data Science With Python
  • Machine Learning with Python

assignment operator x

  • Explore Our Geeks Community
  • How To Do Math in Python 3 with Operators?
  • Python Bitwise Operators
  • Understanding Boolean Logic in Python 3
  • Logical Operators in Python with Examples
  • Difference between "__eq__" VS "is" VS "==" in Python
  • Python - Star or Asterisk operator ( * )
  • Python 3 - Logical Operators
  • Concatenate two strings using Operator Overloading in Python
  • Modulo operator (%) in Python
  • Relational Operators in Python
  • Python | Operator.countOf
  • Python | a += b is not always a = a + b
  • Python Arithmetic Operators
  • Difference between != and is not operator in Python
  • Python Object Comparison : "is" vs "=="
  • Precedence and Associativity of Operators in Python
  • Operator Overloading in Python
  • Python Operators
  • A += B Assignment Riddle in Python

Assignment Operators in Python

Operators are used to perform operations on values and variables. These are the special symbols that carry out arithmetic, logical, bitwise computations. The value the operator operates on is known as Operand .

Here, we will cover Assignment Operators in Python. So, Assignment Operators are used to assigning values to variables. 

Now Let’s see each Assignment Operator one by one.

1) Assign: This operator is used to assign the value of the right side of the expression to the left side operand.

2) Add and Assign: This operator is used to add the right side operand with the left side operand and then assigning the result to the left operand.

Syntax: 

3) Subtract and Assign: This operator is used to subtract the right operand from the left operand and then assigning the result to the left operand.

Example –

 4) Multiply and Assign: This operator is used to multiply the right operand with the left operand and then assigning the result to the left operand.

 5) Divide and Assign: This operator is used to divide the left operand with the right operand and then assigning the result to the left operand.

 6) Modulus and Assign: This operator is used to take the modulus using the left and the right operands and then assigning the result to the left operand.

7) Divide (floor) and Assign: This operator is used to divide the left operand with the right operand and then assigning the result(floor) to the left operand.

 8) Exponent and Assign: This operator is used to calculate the exponent(raise power) value using operands and then assigning the result to the left operand.

9) Bitwise AND and Assign: This operator is used to perform Bitwise AND on both operands and then assigning the result to the left operand.

10) Bitwise OR and Assign: This operator is used to perform Bitwise OR on the operands and then assigning result to the left operand.

11) Bitwise XOR and Assign:  This operator is used to perform Bitwise XOR on the operands and then assigning result to the left operand.

12) Bitwise Right Shift and Assign: This operator is used to perform Bitwise right shift on the operands and then assigning result to the left operand.

 13) Bitwise Left Shift and Assign:  This operator is used to perform Bitwise left shift on the operands and then assigning result to the left operand.

Please Login to comment...

author

  • Python-Operators
  • How To Save A Route On Google Maps
  • How Much YouTube Pays You for 1,000 Views
  • How to Add Date in Google Sheets
  • How to Add Instagram Highlights Without Followers Seeing Your Story
  • 10 Best Free AI Art Generators to Create Image From Text [Free & Paid]

Improve your Coding Skills with Practice

 alt=

C Functions

C structures, c operators.

Operators are used to perform operations on variables and values.

In the example below, we use the + operator to add together two values:

Although the + operator is often used to add together two values, like in the example above, it can also be used to add together a variable and a value, or a variable and another variable:

C divides the operators into the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

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:

Comparison Operators

Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.

The return value of a comparison is either 1 or 0 , which means true ( 1 ) or false ( 0 ). These values are known as Boolean values , and you will learn more about them in the Booleans and If..Else chapter.

Comparison operators are used to compare two values.

Note: The return value of a comparison is either true ( 1 ) or false ( 0 ).

In the following example, we use the greater than operator ( > ) to find out if 5 is greater than 3:

A list of all comparison operators:

Logical Operators

You can also test for true or false values with logical operators.

Logical operators are used to determine the logic between variables or values:

Sizeof Operator

The memory size (in bytes) of a data type or a variable can be found with the sizeof operator:

Note that we use the %lu format specifer to print the result, instead of %d . It is because the compiler expects the sizeof operator to return a long unsigned int ( %lu ), instead of int ( %d ). On some computers it might work with %d , but it is safer to use %lu .

Why Should I Know the Size of Data Types?

Knowing the memory size of different data types is great when you are working with larger programs that require good memory management.

Using the right data type for the right purpose will save memory and improve the performance of your program.

You will learn more about the sizeof operator later in this tutorial, and how to use it in different scenarios.

C Exercises

Test yourself with exercises.

Fill in the blanks to multiply 10 with 5 , and print the result:

Start the Exercise

Get Certified

COLOR PICKER

colorpicker

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

[email protected]

Top Tutorials

Top references, top examples, get certified.

IMAGES

  1. What is Python Assignment Operators? Full List With Types

    assignment operator x

  2. PPT

    assignment operator x

  3. How Matlab Assignment Operator Works (Example)

    assignment operator x

  4. PPT

    assignment operator x

  5. Assignment Operators in C » PREP INSTA

    assignment operator x

  6. Assignment Operators in C

    assignment operator x

VIDEO

  1. Entry Point

  2. How to Take the Percentage of Numbers in C++||Calculate the Percentage||Class 16

  3. Data Entry Complete Course by Sheharyar The Tech Guru

  4. "Python Programming Bootcamp: Complete Tutorial Course for Fast and Effective Learning"

  5. Assignment

  6. OPERATOR x MARSHAL #valorant #valorantclips #valoranthighlights #valorantlive #valorantmontage

COMMENTS

  1. Assignment operators

    The direct assignment operator expects a modifiable lvalue as its left operand and an rvalue expression or a braced-init-list(since C++11) as its right operand, and returns an lvalue identifying the left operand after modification. The result is a bit-field if the left operand is a bit-field.

  2. Expressions and operators

    An assignment operator assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal (=), which assigns the value of its right operand to its left operand.That is, x = f() is an assignment expression that assigns the value of f() to x. There are also compound assignment operators that are shorthand for the operations listed in the ...

  3. Assignment Operators in C

    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.

  4. JavaScript Assignment

    The Simple Assignment Operator assigns a value to a variable. Simple Assignment Examples let x = 10; Try it Yourself » let x = 10 + y; Try it Yourself » The += Operator The Addition Assignment Operator adds a value to a variable. Addition Assignment Examples let x = 10; x += 5; Try it Yourself » let text = "Hello"; text += " World";

  5. C++ 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: Example int x = 10; Try it Yourself » The addition assignment operator ( +=) adds a value to a variable: Example int x = 10; x += 5; Try it Yourself »

  6. Python Assignment Operators

    Python Assignment Operators. Assignment operators are used to assign values to variables: Operator. Example. Same As. Try it. =. x = 5. x = 5.

  7. Assignment operators

    The basic assignment operator is equal ( = ), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following definitions and examples. Name. Shorthand operator.

  8. Python's Assignment Operator: Write Robust Assignments

    Use the as Keyword Access the _ Special Variable in an Interactive Session Illegal and Dangerous Assignments in Python Keywords Built-in Objects Named Constants Conclusion

  9. Assignment operators

    Simple assignment. 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).

  10. Python Operators (With Examples)

    2. Python Assignment Operators. Assignment operators are used to assign values to variables. For example, # assign 5 to x var x = 5. Here, = is an assignment operator that assigns 5 to x. Here's a list of different assignment operators available in Python.

  11. Java 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: Example int x = 10; Try it Yourself » The addition assignment operator ( +=) adds a value to a variable: Example int x = 10; x += 5; Try it Yourself »

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

    9 Answers Sorted by: 798 The difference in assignment operators is clearer when you use them to set an argument value in a function call. For example: median (x = 1:10) x ## Error: object 'x' not found In this case, x is declared within the scope of the function, so it does not exist in the user workspace.

  13. Assignment Operators in C

    A. The most basic assignment operator in the C language is the simple = operator, which is used for assigning a value to a variable. Conclusion. Assignment operators are used to assign the result of an expression to a variable. There are two types of assignment operators in C. Simple assignment operator and compound assignment operator.

  14. Java Assignment Operators with Examples

    1. (=) operator: This is the most straightforward assignment operator, which is used to assign the value on the right to the variable on the left. This is the basic definition of an assignment operator and how it functions. Syntax: num1 = num2;

  15. Assignment Operators in C

    Assignment Operators in C Assignment Operators in C The following table lists the assignment operators supported by the C language − Example Try the following example to understand all the assignment operators available in C − Live Demo

  16. Assignment Operators In C++

    There are 10 compound assignment operators in C++: Addition Assignment Operator ( += ) Subtraction Assignment Operator ( -= ) Multiplication Assignment Operator ( *= ) Division Assignment Operator ( /= ) Modulus Assignment Operator ( %= ) Bitwise AND Assignment Operator ( &= ) Bitwise OR Assignment Operator ( |= )

  17. Augmented Assignment Operators in Python

    Augmented assignment operators have a special role to play in Python programming. It basically combines the functioning of the arithmetic or bitwise operator with the assignment operator. So assume if we need to add 7 to a variable "a" and assign the result back to "a", ...

  18. c++

    A user-declared copy assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X, X&, const X&, volatile X& or const volatile X&. So for example: struct X { int a; // an assignment operator which is not a copy assignment operator X &operator= (int rhs) { a = rhs; return *this ...

  19. Assignment Operators In C [ Full Information With Examples ]

    Example -: 2. Compound Assignment Operators In C. Compound Assignment Operators use the old value of a variable to calculate its new value and reassign the value obtained from the calculation to the same variable. Examples of compound assignment operators are: (Example: + =, - =, * =, / =,% =, & =, ^ =) Here in this example, adding 5 to the x ...

  20. Advanced JavaScript Operators

    The destructuring assignment is a special operator that allows you to "unpack" or "extract" the values of JavaScript arrays and objects. It has become one of the most useful features of JavaScript language for two reasons: It helps you to avoid code repetition. It keeps your code clean and easy to understand.

  21. Assignment Operators in C

    Put And Post Difference. Assignment Operators in C: An assignment operator is basically a binary operator that helps in modifying the variable to its left with the use of the value to its right. We utilize these operators to assign values to any variables. Visit to know more about Assignment Operators in C and other CSE notes for the GATE Exam.

  22. Assignment Operators In C With Proper Code Examples // Unstop (formerly

    Output: The value of x is 8. Code Explanation : The C program above begins with the inclusion of the input/ output header file.. Inside the main() function, we declare an integer variable, x, and initialize it with the value 5 using the simple assignment operator.; Next, we use the addition assignment operator (+=) to add a value to the variable on the left side, i.e., x, and assign the result ...

  23. SpaceX launches first set of satellites with direct-to-cell

    T-Mobile US said on Wednesday SpaceX launched a Falcon 9 rocket on Tuesday with the first set of Starlink satellites that can beam phone signals from space directly to smartphones.

  24. Meet the shrewdest operators in today's oil markets

    It is in this context that you should consider two recent megadeals: ExxonMobil's $64.5bn merger with Pioneer Natural Resources, a fracking giant, and Chevron's $60bn acquisition of Hess, an ...

  25. Coal miners in North Dakota unearth a mammoth tusk buried for thousands

    Too quickly, and the bone could break apart and be destroyed, Person said. North Dakota Geologic Survey Paleontologist Jeff Person sits behind a 7-foot mammoth tusk on Tuesday, Dec. 19, 2023, at ...

  26. Saudi Arabia has an unlikely solar star

    Meet the shrewdest operators in today's oil markets; From the January 6th 2024 edition. Discover stories from this section and more in the list of contents . Explore the edition. Share.

  27. Assignment Operators in Python

    1) Assign: This operator is used to assign the value of the right side of the expression to the left side operand. Syntax: x = y + z Example: Python3 # Assigning values using # Assignment Operator a = 3 b = 5 c = a + b print(c) Output: 8

  28. C Operators

    In the example below, we use the to add together two values: Try it Yourself ». ) adds a value to a variable: Try it Yourself ». The return value of a comparison is either ). These values are known as Boolean values, and you will learn more about them in the. ) to find out if 5 is greater than 3: Try it Yourself ». Try it ».