Don't miss an insight. Subscribe to Techopedia for free.
- Assignment Operator
Table of Contents
What does assignment operator mean, techopedia explains assignment operator.
An assignment operator is the operator used to assign a new value to a variable, property, event or indexer element in C# programming language. Assignment operators can also be used for logical operations such as bitwise logical operations or operations on integral operands and Boolean operands. Unlike in C++, assignment operators in C# cannot be overloaded directly, but the user-defined types can overload the operators like +, -, /, etc. This allows the assignment operator to be used with those types.
The following are the characteristics of assignment operators:
- When using the "=" operator for an assignment with the left operand as the property or indexer access, the property or indexer must have a set accessor.
- Overloading a binary operator implicitly overloads its corresponding assignment operator (if any).
- The different assignment operators are based on the type of operation performed between two operands such as addition (+=), subtraction, (-=), etc. The meaning of the operator symbol used depends on the type of the operands.
- Assignment operators are right-associative, which means they are grouped from right to left.
- Although assignment using assignment operator (a += b) achieves the same result as that without ( =a +b), the difference between the two ways is that unlike in the latter example, "a" is evaluated only once.
- The assignment operator usually returns a reference to the object so as to be used in multiple assignments made in a single statement such as "a=b=c", where a, b and c are operands.
- The assignment operator expects the type of both the left- and right-hand side to be the same for successful assignment.
In C#, an expression using an assignment operator might be "x op y", where x and y are operands and "op" represents the operator. The simple assignment operator "=" is used to store the value of its right-hand operand into the memory location denoted by the left-hand operand. The result is its return value. The other assignment operators that perform indicated operation on the two operands and assign a resulting value to the left operand are called compound assignment operators. These include:
- <<= and >>=
Share this Term
- Conditional Logical Operator
- Boolean Logical Operator
Top 10 highest paying it certifications and how to get them, why does ai have biases, enterprise cybersecurity solutions: 5 steps to take today, 4 principles of responsible artificial intelligence systems.
- How to Run API-Powered Apps: The Future of Enterprise
- 7 Women Leaders in AI, Machine Learning and Robotics
7 Sneaky Ways Hackers Can Get Your Facebook Password
Mastering the Foundations of AI: Top 8 Beginner-Level AI Courses to Try
How to Trace an IP Address
Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
By: Devin Partida | Editor-in-Chief for ReHack.com
By: Leah Zitter | Contributor
By: John Meah | Cyber Security Consultant
By: Kaushik Pal | Contributor
- Data Structure & Algorithm Classes (Live)
- System Design (Live)
- Explore More Live Courses
- Interview Preparation Course
- Data Science (Live)
- GATE CS & IT 2024
- Data Structure & Algorithm-Self Paced(C++/JAVA)
- Data Structures & Algorithms in Python
- Explore More Self-Paced Courses
- C++ Programming - Beginner to Advanced
- Java Programming - Beginner to Advanced
- C Programming - Beginner to Advanced
- Full Stack Development with React & Node JS(Live)
- Java Backend Development(Live)
- Android App Development with Kotlin(Live)
- Python Backend Development with Django(Live)
- Complete Data Science Program(Live)
- Mastering Data Analytics
- DevOps Engineering - Planning to Production
- CBSE Class 12 Computer Science
- School Guide
- All Courses
- Linked List
- Binary Tree
- Binary Search Tree
- Advanced Data Structure
- All Data Structures
- Asymptotic Analysis
- Worst, Average and Best Cases
- Asymptotic Notations
- Little o and little omega notations
- Lower and Upper Bound Theory
- Analysis of Loops
- Solving Recurrences
- Amortized Analysis
- What does 'Space Complexity' mean ?
- Pseudo-polynomial Algorithms
- Polynomial Time Approximation Scheme
- A Time Complexity Question
- Searching Algorithms
- Sorting Algorithms
- Graph Algorithms
- Pattern Searching
- Geometric Algorithms
- Bitwise Algorithms
- Randomized Algorithms
- Greedy Algorithms
- Dynamic Programming
- Divide and Conquer
- Branch and Bound
- All Algorithms
- Company Preparation
- Practice Company Questions
- Interview Experiences
- Experienced Interviews
- Internship Interviews
- Competitive Programming
- Design Patterns
- System Design Tutorial
- Multiple Choice Quizzes
- Go Language
- Tailwind CSS
- Foundation CSS
- Materialize CSS
- Semantic UI
- Angular PrimeNG
- Angular ngx Bootstrap
- jQuery Mobile
- jQuery EasyUI
- React Bootstrap
- React Rebass
- React Desktop
- React Suite
- ReactJS Evergreen
- ReactJS Reactstrap
- English Grammar
- School Programming
- Number System
- Class 8 Syllabus
- Class 9 Syllabus
- Class 10 Syllabus
- Class 11 Syllabus
- Class 8 Notes
- Class 9 Notes
- Class 10 Notes
- Class 11 Notes
- Class 12 Notes
- Class 8 Formulas
- Class 9 Formulas
- Class 10 Formulas
- Class 11 Formulas
- Class 8 Maths Solution
- Class 9 Maths Solution
- Class 10 Maths Solution
- Class 11 Maths Solution
- Class 12 Maths Solution
- Class 7 Notes
- History Class 7
- History Class 8
- History Class 9
- Geo. Class 7
- Geo. Class 8
- Geo. Class 9
- Civics Class 7
- Civics Class 8
- Business Studies (Class 11th)
- Microeconomics (Class 11th)
- Statistics for Economics (Class 11th)
- Business Studies (Class 12th)
- Accountancy (Class 12th)
- Macroeconomics (Class 12th)
- Machine Learning
- Data Science
- Operating System
- Computer Networks
- Computer Organization and Architecture
- Theory of Computation
- Compiler Design
- Digital Logic
- Software Engineering
- GATE 2024 Live Course
- GATE Computer Science Notes
- Last Minute Notes
- GATE CS Solved Papers
- GATE CS Original Papers and Official Keys
- GATE CS 2023 Syllabus
- Important Topics for GATE CS
- GATE 2023 Important Dates
- Software Design Patterns
- HTML Cheat Sheet
- CSS Cheat Sheet
- Bootstrap Cheat Sheet
- JS Cheat Sheet
- jQuery Cheat Sheet
- Angular Cheat Sheet
- Facebook SDE Sheet
- Amazon SDE Sheet
- Apple SDE Sheet
- Netflix SDE Sheet
- Google SDE Sheet
- Wipro Coding Sheet
- Infosys Coding Sheet
- TCS Coding Sheet
- Cognizant Coding Sheet
- HCL Coding Sheet
- FAANG Coding Sheet
- Love Babbar Sheet
- Mass Recruiter Sheet
- Product-Based Coding Sheet
- Company-Wise Preparation Sheet
- Array Sheet
- String Sheet
- Graph Sheet
- ISRO CS Original Papers and Official Keys
- ISRO CS Solved Papers
- ISRO CS Syllabus for Scientist/Engineer Exam
- UGC NET CS Notes Paper II
- UGC NET CS Notes Paper III
- UGC NET CS Solved Papers
- Campus Ambassador Program
- School Ambassador Program
- Geek of the Month
- Campus Geek of the Month
- Placement Course
- Student Chapter
- Geek on the Top
- Geography Notes
- History Notes
- Science & Tech. Notes
- Ethics Notes
- Polity Notes
- Economics Notes
- UPSC Previous Year Papers
- SSC CGL Syllabus
- General Studies
- Subjectwise Practice Papers
- Previous Year Papers
- SBI Clerk Syllabus
- General Awareness
- Quantitative Aptitude
- Reasoning Ability
- SBI Clerk Practice Papers
- SBI PO Syllabus
- SBI PO Practice Papers
- IBPS PO 2022 Syllabus
- English Notes
- Reasoning Notes
- Mock Question Papers
- IBPS Clerk Syllabus
- Apply for a Job
- Apply through Jobathon
- Hire through Jobathon
- All DSA Problems
- Problem of the Day
- GFG SDE Sheet
- Top 50 Array Problems
- Top 50 String Problems
- Top 50 Tree Problems
- Top 50 Graph Problems
- Top 50 DP Problems
- Solving For India-Hackthon
- GFG Weekly Coding Contest
- Job-A-Thon: Hiring Challenge
- BiWizard School Contest
- All Contests and Events
- Saved Videos
- What's New ?
- Data Structures
- Interview Preparation
- Topic-wise Practice
- Latest Blogs
- Write & Earn
- Web Development
- Write Articles
- Pick Topics to write
- Guidelines to Write
- Get Technical Writing Internship
- Write an Interview Experience
- Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
- Arrays in C/C++
- std::sort() in C++ STL
- Bitwise Operators in C/C++
- Segmentation Fault in C/C++
- Multidimensional Arrays in C / C++
- Left Shift and Right Shift Operators in C/C++
- Substring in C++
- rand() and srand() in C++
- Different Methods to Reverse a String in C++
- What is Memory Leak? How can we avoid?
- Command Line Arguments in C/C++
- Enumeration (or enum) in C
- std::string class in C++
- Function Pointer in C
- fork() in C
- C Language Introduction
- Strings in C
- Data Types in C
- Structures in C
- Power Function in C/C++
- INT_MAX and INT_MIN in C/C++ and Applications
- Taking String input with space in C (4 Different Methods)
- Modulo Operator (%) in C/C++ with Examples
- Pointer to an Array | Array Pointer
- Memory Layout of C Programs
- Static Variables in C
- TCP Server-Client implementation in C
- Functions in C++
Assignment Operators in C/C++
- Difficulty Level : Easy
- Last Updated : 11 Oct, 2019
Assignment operators are used to assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of the variable on the left side otherwise the compiler will raise an error. Different types of assignment operators are shown below:
- “=” : This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. For example: a = 10; b = 20; ch = 'y';
Please Login to comment...
New Course Launch!
Improve your Coding Skills with Practice
Start your coding journey now.
Want to create or adapt books like this? Learn more about how Pressbooks supports open publishing practices.
Kenneth Leroy Busbee
An assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable. 
The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within most programming languages the symbol used for assignment is the equal symbol. But bite your tongue, when you see the = symbol you need to start thinking: assignment. The assignment operator has two operands. The one to the left of the operator is usually an identifier name for a variable. The one to the right of the operator is a value.
The value 21 is moved to the memory location for the variable named: age. Another way to say it: age is assigned the value 21.
Assignment with an Expression
The item to the right of the assignment operator is an expression. The expression will be evaluated and the answer is 14. The value 14 would be assigned to the variable named: total_cousins.
Assignment with Identifier Names in the Expression
The expression to the right of the assignment operator contains some identifier names. The program would fetch the values stored in those variables; add them together and get a value of 44; then assign the 44 to the total_students variable.
- cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
- Wikipedia: Assignment (computer science) ↵
Programming Fundamentals by Kenneth Leroy Busbee is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License , except where otherwise noted.
Share This Book
- Coding Ground
- Corporate Training
- 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 −
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
- 5 minutes to read
- 7 contributors
expression assignment-operator expression
assignment-operator : one of = *= /= %= += -= <<= >>= &= ^= |=
Assignment operators store a value in the object specified by the left operand. There are two kinds of assignment operations:
simple assignment , in which the value of the second operand is stored in the object specified by the first operand.
compound assignment , in which an arithmetic, shift, or bitwise operation is performed before storing the result.
All assignment operators in the following table except the = operator are compound assignment operators.
Assignment operators table
Three of the compound assignment operators have keyword equivalents. They are:
C++ specifies these operator keywords as alternative spellings for the compound assignment operators. In C, the alternative spellings are provided as macros in the <iso646.h> header. In C++, the alternative spellings are keywords; use of <iso646.h> or the C++ equivalent <ciso646> is deprecated. In Microsoft C++, the /permissive- or /Za compiler option is required to enable the alternative spelling.
The simple assignment operator ( = ) causes the value of the second operand to be stored in the object specified by the first operand. If both objects are of arithmetic types, the right operand is converted to the type of the left, before storing the value.
Objects of const and volatile types can be assigned to l-values of types that are only volatile , or that aren't const or volatile .
Assignment to objects of class type ( struct , union , and class types) is performed by a function named operator= . The default behavior of this operator function is to perform a bitwise copy; however, this behavior can be modified using overloaded operators. For more information, see Operator overloading . Class types can also have copy assignment and move assignment operators. For more information, see Copy constructors and copy assignment operators and Move constructors and move assignment operators .
An object of any unambiguously derived class from a given base class can be assigned to an object of the base class. The reverse isn't true because there's an implicit conversion from derived class to base class, but not from base class to derived class. For example:
Assignments to reference types behave as if the assignment were being made to the object to which the reference points.
For class-type objects, assignment is different from initialization. To illustrate how different assignment and initialization can be, consider the code
The preceding code shows an initializer; it calls the constructor for UserType2 that takes an argument of type UserType1 . Given the code
the assignment statement
can have one of the following effects:
Call the function operator= for UserType2 , provided operator= is provided with a UserType1 argument.
Call the explicit conversion function UserType1::operator UserType2 , if such a function exists.
Call a constructor UserType2::UserType2 , provided such a constructor exists, that takes a UserType1 argument and copies the result.
The compound assignment operators are shown in the Assignment operators table . These operators have the form e1 op = e2 , where e1 is a non- const modifiable l-value and e2 is:
an arithmetic type
a pointer, if op is + or -
The e1 op = e2 form behaves as e1 = e1 op e2 , but e1 is evaluated only once.
Compound assignment to an enumerated type generates an error message. If the left operand is of a pointer type, the right operand must be of a pointer type, or it must be a constant expression that evaluates to 0. When the left operand is of an integral type, the right operand must not be of a pointer type.
Result of assignment operators
The assignment operators return the value of the object specified by the left operand after the assignment. The resultant type is the type of the left operand. The result of an assignment expression is always an l-value. These operators have right-to-left associativity. The left operand must be a modifiable l-value.
In ANSI C, the result of an assignment expression isn't an l-value. That means the legal C++ expression (a += b) += c isn't allowed in C.
Expressions with binary operators C++ built-in operators, precedence, and associativity C assignment operators
Submit and view feedback for
Assignment Operators in C
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.
- This article defines what are Assignment Operators in the C programming language.
- In this article, we will learn about all kinds of assignment operators in the C language using examples.
Assignment Operators help us to assign the value or result of an expression to a variable and the value on the right side must be of the same data type as the variable on the left side. They have the lowest precedence level among all the operators, and it associates from right to left. The most commonly used Assignment Operator is = . Also, Assignment Operators fall under the category of Binary Operators.
For example, x = 4 ; then that means value 4 is assigned to variable x or we can say that variable x holds value 4 .
Let me explain to you more about Assignment Operators. Don't worry after this section, you will fully understand the definition of Assignment Operators in C.
Our example is x = 4 , so what does it tell us?
- It simply says, " hey variable x please hold a value 4 which I give you as I wrote in the definition."
So can we say that always variables are on the Left Hand Side of the assignment operator and values are always on the Right Hand Side of the operator? YES . Please take a look at the image it will help you to understand more about the above wording.
The above diagram helps us to understand that the RHS value is assigned to the LHS variable.
The LHS and RHS are known as Operands.
So the operand on the LHS of the assignment operator must be a variable and operand on RHS must be a constant , variable or expression . For example:
As mentioned, precedence levels of assignment operators are lower than all the operators we have discussed so far and it associates from right to left. Now you may wonder what do you mean by it associates from right to left? Let's understand this together.
This is totally correct and means we can also assign the same value to multiple variables with one single line of code .
So what do you get from the above line of code? Simply, variable_x , variable_y and variable_z hold the same value. YES!! TRUE. But how?
The main question is here how value is assigned to them? is first variable_x get 10 or variable_y or variable_z ? What do you say? This answer is given by the line: It associates from right to left .
So that means we have to read the line from the right side to the left. Like, at first 10 is given to variable_z then variable_y gets the value present in the variable_z and after that variable_x get the value present in the variable_y . So the above wording is equivalent to the following expression.
This is the simplest explanation about assignment operator associativity.
The most basic Assignment operator is = . It requires two operands for its work. For example, = x doesn't make any sense but variable = x makes sense because it clearly says the variable variable stores the value of x . Therefore, Assignment operators are Binary operators.
Hopefully, every point in the definition is now clear to all of you.
List of All Assignment Operators in C
We have 2 types of Assignment Operators in C :
- Simple Assignment operator (Example : = ) .
- Compound Assignment Operators (Example : += , -= , &= ) .
Simple Assignment Operator in C
It is the operator used to assign the Right Operand to Left Operand . There is only one simple Assignment Operator and that is = . The general Syntax is like Left Operand = Right Operand .
Compound Assignment Operators in C
Any Binary Operator with a simple Assignment Operator will form Compound Assignment Operators.
The general syntax is like Left operand operation = Right operand . Here, the operation is what you want + , - , *, etc.
Let's take an example:
Here read carefully. After which, you will never forget how to read the syntax of a compound assignment operator.
So we read like this FIRST ADD 10 to variable_x , THEN WHATEVER THE RESULT, ASSIGN THAT RESULT TO variable_x . That means the above line of code is equal to
List 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 program for Assignment Operators in C
This is a simple Assignment Operator.
This is the Addition Assignment Operator . In which the left operand becomes equal to the addition of the right operand and left operand.
In this program, x+=y means x+y , so we assign the result of x+y to x .
This is the Subtraction Assignment Operator .
In which left operand becomes equal to the subtraction of right operator from left operand.
The program performs the subtraction of two numbers i.e. x-=y means x = x-y . So the output is :
The main purpose of this operator is that this left operand becomes equal to the product of the left and right operand. This is the Multiplication Assignment Operator .
The program performs the multiplication of two numbers and then the result of the multiplication is assigned to the variable x .
This one is Division Assignment Operator . In this, the left operand becomes equal to the division of the left and right operand.
This program performs a division of two numbers and the result is assigned to x variable i.e. x/=y is the same as x = x/y .
It is well known Modulus Assignment Operator . In this , left operand becomes equal to the modulo of left and right operand.
In this program, the user checks the remainder of two number and assign that remainder to x variable.
This is called the Left Shift Assignment Operator . For example x <<= y so in this, x becomes equal to x left shifted by y .
The program basically shifts every bit of x to the left side by y places and then assigns the result to x .
This is called the Right Shift Assignment Operator . For example x >>= y so , x becomes equal to x right shifted by y .
The program has defined the result of expression when x is right-shifted by y places and the result is going to store in x variable.
This operator is called the Bitwise AND Assignment Operator . Left operand becomes equal to the bitwise AND of left and right operand.
The program performs Bitwise AND operation on every bit of x and y . After that result is going to be stored in variable x .
This is called the Bitwise Inclusive OR Assignment Operator Left operand becomes equal to bitwise OR of left and right operand.
like Bitwise AND Assignment Operator , this program also performs Bitwise OR operation on every bit of x and y . And after that result is going to store in x .
This is called the Bitwise Exclusive OR Assignment Operator Left operand becomes equal to bitwise XOR of left and right operand.
This will perform Bitwise XOR operation on every bit of x and y . After that result is going to store in x .
This is the detailed explanation with programs of all the assignment operators in C that we have. Hopefully, This is clear to you.
Happy Coding folks!!!
- 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.
An assignment operator is the operator used to assign a new value to a variable, property, event or indexer element in C# programming
Assignment operators are used to assigning value to a variable. The left side operand of the assignment operator is a variable and right
The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated
Assignment Operators in C ; = Simple assignment operator. Assigns values from right side operands to left side operand, C = A + B will assign the value of A + B
In the C++ programming language, the assignment operator, = , is the operator used for assignment. Like most other operators in C++, it can be overloaded.
Many other notations are also in use. In some languages, the symbol used is regarded as an operator (meaning that the assignment statement as a whole returns a
An assignment operation assigns the value of the right-hand operand to the storage location named by the left-hand operand.
Assignment operators store a value in the object specified by the left operand. There are two kinds of assignment operations:.
An assignment expression stores a value in the object designated by the left operand. There are two types of assignment operators: ... The left operand in all
Assignment Operators help us to assign the value or result of an expression to a variable and the value on the right side must be of the same