cppreference.com

Assignment operators.

(C11)
Miscellaneous
General
(C11)
(C99)

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

Operator Operator name Example Description Equivalent of
= basic assignment a = b becomes equal to
+= addition assignment a += b becomes equal to the addition of and a = a + b
-= subtraction assignment a -= b becomes equal to the subtraction of from a = a - b
*= multiplication assignment a *= b becomes equal to the product of and a = a * b
/= division assignment a /= b becomes equal to the division of by a = a / b
%= modulo assignment a %= b becomes equal to the remainder of divided by a = a % b
&= bitwise AND assignment a &= b becomes equal to the bitwise AND of and a = a & b
|= bitwise OR assignment a |= b becomes equal to the bitwise OR of and a = a | b
^= bitwise XOR assignment a ^= b becomes equal to the bitwise XOR of and a = a ^ b
<<= bitwise left shift assignment a <<= b becomes equal to left shifted by a = a << b
>>= bitwise right shift assignment a >>= b becomes equal to right shifted by a = a >> b
Simple assignment Notes Compound assignment References See Also See also

[ edit ] Simple assignment

The simple assignment operator expressions have the form

lhs rhs
lhs - expression of any complete object type
rhs - expression of any type to lhs or with lhs

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)
has type (possibly qualified or atomic(since C11)) _Bool and rhs is a pointer or a value(since C23) (since C99)
has type (possibly qualified or atomic) and rhs has type (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

lhs op rhs
op - one of *=, /= %=, += -=, <<=, >>=, &=, ^=, |=
lhs, rhs - expressions with (where lhs may be qualified or atomic), except when op is += or -=, which also accept pointer types with the same restrictions as + and -

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

If lhs has type, the operation behaves as a single atomic read-modify-write operation with memory order .

For integer atomic types, the compound assignment @= is equivalent to:

addr = &lhs; T2 val = rhs; T1 old = *addr; T1 new; do { new = old @ val } while (! (addr, &old, new);
(since C11)

[ 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

Common operators

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

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

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

!a
a && b
a || b

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

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

a(...)
a, b
(type) a
a ? b : c
sizeof


_Alignof
(since C11)

[ edit ] See also

for Assignment operators
  • Recent changes
  • Offline version
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link
  • Page information
  • In other languages
  • This page was last modified on 19 August 2022, at 09:36.
  • This page has been accessed 58,085 times.
  • Privacy policy
  • About cppreference.com
  • Disclaimers

Powered by MediaWiki

CProgramming Tutorial

  • C Programming Tutorial
  • C - Overview
  • C - Features
  • C - History
  • C - Environment Setup
  • C - Program Structure
  • C - Hello World
  • C - Compilation Process
  • C - Comments
  • C - Keywords
  • C - Identifiers
  • C - User Input
  • C - Basic Syntax
  • C - Data Types
  • C - Variables
  • C - Integer Promotions
  • C - Type Conversion
  • C - Booleans
  • C - Constants
  • C - Literals
  • C - Escape sequences
  • C - Format Specifiers
  • C - Storage Classes
  • C - Operators
  • C - Arithmetic Operators
  • C - Relational Operators
  • C - Logical Operators
  • C - Bitwise Operators
  • C - Assignment Operators
  • C - Unary Operators
  • C - Increment and Decrement Operators
  • C - Ternary Operator
  • C - sizeof Operator
  • C - Operator Precedence
  • C - Misc Operators
  • C - Decision Making
  • C - if statement
  • C - if...else statement
  • C - nested if statements
  • C - switch statement
  • C - nested switch statements
  • C - While loop
  • C - For loop
  • C - Do...while loop
  • C - Nested loop
  • C - Infinite loop
  • C - Break Statement
  • C - Continue Statement
  • C - goto Statement
  • C - Functions
  • C - Main Functions
  • C - Function call by Value
  • C - Function call by reference
  • C - Nested Functions
  • C - Variadic Functions
  • C - User-Defined Functions
  • C - Callback Function
  • C - Return Statement
  • C - Recursion
  • C - Scope Rules
  • C - Static Variables
  • C - Global Variables
  • C - Properties of Array
  • C - Multi-Dimensional Arrays
  • C - Passing Arrays to Function
  • C - Return Array from Function
  • C - Variable Length Arrays
  • C - Pointers
  • C - Pointers and Arrays
  • C - Applications of Pointers
  • C - Pointer Arithmetics
  • C - Array of Pointers
  • C - Pointer to Pointer
  • C - Passing Pointers to Functions
  • C - Return Pointer from Functions
  • C - Function Pointers
  • C - Pointer to an Array
  • C - Pointers to Structures
  • C - Chain of Pointers
  • C - Pointer vs Array
  • C - Character Pointers and Functions
  • C - NULL Pointer
  • C - void Pointer
  • C - Dangling Pointers
  • C - Dereference Pointer
  • C - Near, Far and Huge Pointers
  • C - Initialization of Pointer Arrays
  • C - Pointers vs. Multi-dimensional Arrays
  • C - Strings
  • C - Array of Strings
  • C - Special Characters
  • C - Structures
  • C - Structures and Functions
  • C - Arrays of Structures
  • C - Self-Referential Structures
  • C - Lookup Tables
  • C - Dot (.) Operator
  • C - Enumeration (or enum)
  • C - Nested Structures
  • C - Structure Padding and Packing
  • C - Anonymous Structure and Union
  • C - Bit Fields
  • C - Typedef
  • C - Input & Output
  • C - File I/O
  • C - Preprocessors
  • C - Pragmas
  • C - Preprocessor Operators
  • C - Header Files
  • C - Type Casting
  • C - Error Handling
  • C - Variable Arguments
  • C - Memory Management
  • C - Command Line Arguments
  • C Programming 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

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

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

In addition, C has several augmented assignment operators.

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

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

Simple Assignment Operator (=)

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

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

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

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

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

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

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

Augmented Assignment Operators

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

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

Run the code and check its output −

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

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

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

To Continue Learning Please Login

Learn to Code, Prepare for Interviews, and Get Hired

01 Career Opportunities

  • Top 50 Mostly Asked C Interview Questions and Answers

02 Beginner

  • If Statement in C
  • Understanding do...while loop in C
  • Understanding for loop in C
  • if else if statements in C Programming
  • If...else statement in C Programming
  • Understanding realloc() function in C
  • Understanding While loop in C
  • Why C is called middle level language?
  • Beginner's Guide to C Programming
  • First C program and Its Syntax
  • Escape Sequences and Comments in C
  • Keywords in C: List of Keywords
  • Identifiers in C: Types of Identifiers
  • Data Types in C Programming - A Beginner Guide with examples
  • Variables in C Programming - Types of Variables in C ( With Examples )
  • 10 Reasons Why You Should Learn C
  • Boolean and Static in C Programming With Examples ( Full Guide )
  • Operators in C: Types of Operators
  • Bitwise Operators in C: AND, OR, XOR, Shift & Complement
  • Expressions in C Programming - Types of Expressions in C ( With Examples )
  • Conditional Statements in C: if, if..else, Nested if
  • Switch Statement in C: Syntax and Examples
  • Ternary Operator in C: Ternary Operator vs. if...else Statement
  • Loop in C with Examples: For, While, Do..While Loops
  • Nested Loops in C - Types of Expressions in C ( With Examples )
  • Infinite Loops in C: Types of Infinite Loops
  • Jump Statements in C: break, continue, goto, return
  • Continue Statement in C: What is Break & Continue Statement in C with Example

03 Intermediate

  • Constants in C language
  • Getting Started with Data Structures in C
  • Functions in C Programming
  • Call by Value and Call by Reference in C
  • Recursion in C: Types, its Working and Examples
  • Storage Classes in C: Auto, Extern, Static, Register
  • Arrays in C Programming: Operations on Arrays
  • Strings in C with Examples: String Functions

04 Advanced

  • How to Dynamically Allocate Memory using calloc() in C?
  • How to Dynamically Allocate Memory using malloc() in C?
  • Pointers in C: Types of Pointers
  • Multidimensional Arrays in C: 2D and 3D Arrays
  • Dynamic Memory Allocation in C: Malloc(), Calloc(), Realloc(), Free()

05 Training Programs

  • Java Programming Course
  • C++ Programming Course
  • C Programming Course
  • Data Structures and Algorithms Training
  • C Programming Assignment ..

C Programming Assignment Operators

C Programming Assignment Operators

multiplying assignment operator c

C Programming For Beginners Free Course

What is an assignment operator in c.

Assignment Operators in C are used to assign values to the variables. They come under the category of binary operators as they require two operands to operate upon. The left side operand is called a variable and the right side operand is the value. The value on the right side of the "=" is assigned to the variable on the left side of "=". The value on the right side must be of the same data type as the variable on the left side. Hence, the associativity is from right to left.

In this C tutorial , we'll understand the types of C programming assignment operators with examples. To delve deeper you can enroll in our C Programming Course .

Before going in-depth about assignment operators you must know about operators in C. If you haven't visited the Operators in C tutorial, refer to Operators in C: Types of Operators .

Types of Assignment Operators in C

There are two types of assignment operators in C:

Types of Assignment Operators in C
+=addition assignmentIt adds the right operand to the left operand and assigns the result to the left operand.
-=subtraction assignmentIt subtracts the right operand from the left operand and assigns the result to the left operand.
*=multiplication assignmentIt multiplies the right operand with the left operand and assigns the result to the left operand
/=division assignmentIt divides the left operand with the right operand and assigns the result to the left operand.
%=modulo assignmentIt takes modulus using two operands and assigns the result to the left operand.

Example of Augmented Arithmetic and Assignment Operators

There can be five combinations of bitwise operators with the assignment operator, "=". Let's look at them one by one.

&=bitwise AND assignmentIt performs the bitwise AND operation on the variable with the value on the right
|=bitwise OR assignmentIt performs the bitwise OR operation on the variable with the value on the right
^=bitwise XOR assignmentIt performs the bitwise XOR operation on the variable with the value on the right
<<=bitwise left shift assignmentShifts the bits of the variable to the left by the value on the right
>>=bitwise right shift assignmentShifts the bits of the variable to the right by the value on the right

Example of Augmented Bitwise and Assignment Operators

Practice problems on assignment operators in c, 1. what will the value of "x" be after the execution of the following code.

The correct answer is 52. x starts at 50, increases by 5 to 55, then decreases by 3 to 52.

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

The correct answer is 144. After right-shifting 73 (binary 1001001) by one and then left-shifting the result by two, the value becomes 144 (binary 10010000).

Benefits of Using Assignment Operators

  • Simplifies Code: For example, x += 1 is shorter and clearer than x = x + 1.
  • Reduces Errors: They break complex expressions into simpler, more manageable parts thus reducing errors.
  • Improves Readability: They make the code easier to read and understand by succinctly expressing common operations.
  • Enhances Performance: They often operate in place, potentially reducing the need for additional memory or temporary variables.

Best Practices and Tips for Using the Assignment Operator

While performing arithmetic operations with the same variable, use compound assignment operators

  • Initialize Variables When Declaring int count = 0 ; // Initialization
  • Avoid Complex Expressions in Assignments a = (b + c) * (d - e); // Consider breaking it down: int temp = b + c; a = temp * (d - e);
  • Avoid Multiple Assignments in a Single Statement // Instead of this a = b = c = 0 ; // Do this a = 0 ; b = 0 ; c = 0 ;
  • Consistent Formatting int result = 0 ; result += 10 ;

When mixing assignments with other operations, use parentheses to ensure the correct order of evaluation.

Live Classes Schedule

ASP.NET Core Certification Training Jun 14 MON, WED, FRI Filling Fast
Advanced Full-Stack .NET Developer Certification Training Jun 14 MON, WED, FRI Filling Fast
Angular Certification Course Jun 16 SAT, SUN Filling Fast
ASP.NET Core (Project) Jun 23 SAT, SUN Filling Fast
Azure Developer Certification Training Jun 23 SAT, SUN Filling Fast
Generative AI For Software Developers Jun 23 SAT, SUN Filling Fast
React JS Certification Training | Best React Training Course Jun 30 SAT, SUN Filling Fast

Can't find convenient schedule? Let us know

About Author

Author image

  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support

We use cookies to make interactions with our websites and services easy and meaningful. Please read our Privacy Policy for more details.

Home » Learn C Programming from Scratch » C Assignment Operators

C Assignment Operators

Summary : in this tutorial, you’ll learn about the C assignment operators and how to use them effectively.

Introduction to the C assignment operators

An assignment operator assigns the vale of the right-hand operand to the left-hand operand. The following example uses the assignment operator (=) to assign 1 to the counter variable:

After the assignmment, the counter variable holds the number 1.

The following example adds 1 to the counter and assign the result to the counter:

The = assignment operator is called a simple assignment operator. It assigns the value of the left operand to the right operand.

Besides the simple assignment operator, C supports compound assignment operators. A compound assignment operator performs the operation specified by the additional operator and then assigns the result to the left operand.

The following example uses a compound-assignment operator (+=):

The expression:

is equivalent to the following expression:

The following table illustrates the compound-assignment operators in C:

OperatorOperation PerformedExampleEquivalent expression
Multiplication assignmentx *= yx = x * y
Division assignmentx /= yx = x / y
Remainder assignmentx %= yx = x % y
Addition assignmentx += yx = x + y
Subtraction assignmentx -= yx = x – y
Left-shift assignmentx <<= yx = x <<=y
Right-shift assignmentx >>=yx = x >>= y
Bitwise-AND assignmentx &= yx = x & y
Bitwise-exclusive-OR assignmentx ^= yx = x ^ y
Bitwise-inclusive-OR assignmentx |= yx = x | y
  • A simple assignment operator assigns the value of the left operand to the right operand.
  • A compound assignment operator performs the operation specified by the additional operator and then assigns the result to the left operand.

This browser is no longer supported.

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

C Assignment Operators

  • 6 contributors

An assignment operation assigns the value of the right-hand operand to the storage location named by the left-hand operand. Therefore, the left-hand operand of an assignment operation must be a modifiable l-value. After the assignment, an assignment expression has the value of the left operand but isn't an l-value.

assignment-expression :   conditional-expression   unary-expression assignment-operator assignment-expression

assignment-operator : one of   = *= /= %= += -= <<= >>= &= ^= |=

The assignment operators in C can both transform and assign values in a single operation. C provides the following assignment operators:

Operator Operation Performed
Simple assignment
Multiplication assignment
Division assignment
Remainder assignment
Addition assignment
Subtraction assignment
Left-shift assignment
Right-shift assignment
Bitwise-AND assignment
Bitwise-exclusive-OR assignment
Bitwise-inclusive-OR assignment

In assignment, the type of the right-hand value is converted to the type of the left-hand value, and the value is stored in the left operand after the assignment has taken place. The left operand must not be an array, a function, or a constant. The specific conversion path, which depends on the two types, is outlined in detail in Type Conversions .

  • Assignment Operators

Was this page helpful?

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

Submit and view feedback for

Additional resources

Print Cheatsheet

Mathmatical Symbols in C

C is able to perform basic mathematical operations on variables and values using the following symbols:

  • Addition: +
  • Subtraction: -
  • Division: /
  • Multiplication: *
  • Incrementing: ++
  • Decrementing: --

Assignment Operations in C

C can assign values to variables and perform basic mathematical operations using shorthand operators:

  • Assignment: =
  • Addition then assignment: +=
  • Subtraction then assignment: -=
  • Multiplication then assignment: *=
  • Division then assignment: /=
  • Modulo then assignment: %=

Comparing values in C

C can compare two values and/or variables against each other to return true or false. The operators are as follows:

  • Do both sides have the same value? ==
  • Do the two sides have different values? !=
  • Is the left side a lower value than the right side? <
  • Is the left side a lower or equal value to the right side? <=
  • Is the left side a greater value than the right side? >
  • Is the left side a greater or equal value to the right side? >=

Logical Operators in C

C can perform logical operations using the following operators:

  • and: && (Are both sides true?)
  • or: || (Is at least one side true?)
  • not: ! (True becomes false and false becomes true.)

Multiplication-Assign Operator *=

This page was translated by a robot.

The multiplication-assignment operator multiplies the value to the right of the operator by the value of the variable to the left of the operator and stores the result back into the variable.

The multiplication assignment operator expects an lvalue on the left and an rvalue on the right and is processed from right to left . The return value is an rvalue in C : the value of the left operand after assignment. in C++, the return value is an lvalue : the (now assigned) left operand itself.

The multiplication-assignment operator behaves exactly like the assignment operator except that it performs an additional multiplication. For details about the properties of a multiplication assignment, reference is made here to the description of the assignment operator and the multiplication operator . The following two program lines, which are absolutely equivalent, suffice as an additional explanation of the multiplication-assignment operator in relation to the simple assignment operator ::

The set round brackets indicate that due to the operator ranking in the multiplication assignment as well as in all assignment operators, the complete right-hand part after the equals sign is evaluated as an operand.

Freshers.in

Igniting the Spark of Knowledge

Demystifying Assignment Operators in C Programming

C Programming @ Freshers.in

Assignment operators are fundamental in C programming, as they allow you to assign values and manipulate variables efficiently. In this article, we’ll explore the basics of C programming’s assignment operators: = (Assignment), += (Add and assign), -= (Subtract and assign), *= (Multiply and assign), /= (Divide and assign), and %= (Modulus and assign). Through real-world examples and output demonstrations, you’ll gain a solid understanding of how to use these operators effectively in your C programs. Assignment operators are vital tools in C programming, allowing you to manipulate variables and perform calculations efficiently. In this article, we will explore the basic assignment operators (=, +=, -=, *=, /=, and %=) with real-world examples and output demonstrations.

Assignment Operator (=)

The assignment operator ( = ) is used to assign a value to a variable. It’s the simplest assignment operator. Let’s illustrate this with an example:

Add and Assign (+=)

The += operator is used to add a value to the current value of a variable and assign the result back to the variable. Here’s an example:

Subtract and Assign (-=)

The -= operator is used to subtract a value from the current value of a variable and assign the result back to the variable. Let’s see it in action:

Multiply and Assign (*=)

The *= operator is used to multiply the current value of a variable by a value and assign the result back to the variable. Here’s an example:

Divide and Assign (/=)

The /= operator is used to divide the current value of a variable by a value and assign the result back to the variable. Let’s demonstrate it:

Modulus and Assign (%=)

The %= operator is used to calculate the modulus of the current value of a variable and a value and assign the result back to the variable. Here’s an example:

' src=

Related Articles

multiplying assignment operator c

DBT Python Numpy PySpark Hive Snowflake Redshift Airflow Aptitude

Recent Posts

Featured posts – slider widget, production and industrial engineering, engineering technical campus placement question and answers.

Java Script @ Freshers.in

JavaScript’s reduceRight() method to iterate over an array from right to left

python @ Freshers.in

Merging Multiple Images into a Single PDF File Using Python

Nanotechnology, electronics and instrumentation, chemical engineering, civil engineering.

Kinesis @ Freshers.in

Backpressure in AWS Kinesis Streams: Optimizing Data Processing

Kinesis @ Freshers.in

Troubleshooting Data Ingestion and Processing Issues with AWS Kinesis Streams

Most viewed posts.

  • dbt (data build tool) interview questions
  • Python throwing as NameError: name ‘__file__’ is not defined – Solution
  • DBT command not found after intalling DBT-How to resolve.
  • BigQuery : Handle missing or null values in BigQuery
  • Airflow dags not getting refreshed/updating. How to do it manually?
  • How to delete a partition data as well from Hive external table on DROP command?
  • PySpark – groupby with aggregation (count, sum, mean, min, max)

Copyright © 2024 Freshers.in

  • TutorialKart
  • SAP Tutorials
  • Salesforce Admin
  • Salesforce Developer
  • Visualforce
  • Informatica
  • Kafka Tutorial
  • Spark Tutorial
  • Tomcat Tutorial
  • Python Tkinter

Programming

  • Bash Script
  • Julia Tutorial
  • CouchDB Tutorial
  • MongoDB Tutorial
  • PostgreSQL Tutorial
  • Android Compose
  • Flutter Tutorial
  • Kotlin Android

Web & Server

  • Selenium Java
  • C++ Tutorials
  • C++ Tutorial
  • C++ Hello World Program
  • C++ Comments
  • C++ Variables
  • Print datatype of variable
  • C++ If Else
  • Addition Operator
  • Subtraction Operator
  • Multiplication Operator
  • Division Operator
  • Modulus Operator
  • Increment Operator
  • Decrement Operator
  • Simple Assignment
  • Addition Assignment
  • Subtraction Assignment
  • Multiplication Assignment
  • Division Assignment
  • Remainder Assignment
  • Bitwise AND Assignment
  • ADVERTISEMENT
  • Bitwise OR Assignment
  • Bitwise XOR Assignment
  • Left Shift Assignment
  • Right Shift Assignment
  • Bitwise AND
  • Bitwise XOR
  • Bitwise Complement
  • Bitwise Left shift
  • Bitwise Right shift
  • Logical AND
  • Logical NOT
  • Not Equal to
  • Greater than
  • Greater than or Equal to
  • Less than or Equal to
  • Ternary Operator
  • Do-while loop
  • Infinite While loop
  • Infinite For loop
  • C++ Recursion
  • Create empty string
  • String length
  • String comparison
  • Get character at specific index
  • Get first character
  • Get last character
  • Find index of substring
  • Iterate over characters
  • Print unique characters
  • Check if strings are equal
  • Append string
  • Concatenate strings
  • String reverse
  • String replace
  • Swap strings
  • Convert string to uppercase
  • Convert string to lowercase
  • Append character at end of string
  • Append character to beginning of string
  • Insert character at specific index
  • Remove last character
  • Replace specific character
  • Convert string to integer
  • Convert integer to string
  • Convert string to char array
  • Convert char array to string
  • Initialize array
  • Array length
  • Print array
  • Loop through array
  • Basic array operations
  • Array of objects
  • Array of arrays
  • Convert array to vector
  • Sum of elements in array
  • Average of elements in array
  • Find largest number in array
  • Find smallest number in array
  • Sort integer array
  • Find string with least length in array
  • Create an empty vector
  • Create vector of specific size
  • Create vector with initial values
  • Copy a vector to another
  • Vector length or size
  • Vector of vectors
  • Vector print elements
  • Vector iterate using For loop
  • Vector iterate using While loop
  • Vector Foreach
  • Get reference to element at specific index
  • Check if vector is empty
  • Check if vectors are equal
  • Check if vector contains element
  • Update/Transform
  • Add element(s) to vector
  • Append element to vector
  • Append vector
  • Insert element at the beginning of vector
  • Remove first element from vector
  • Remove last element from vector
  • Remove element at specific index from vector
  • Remove duplicates from vector
  • Remove elements from vector based on condition
  • Resize vector
  • Swap elements of two vectors
  • Remove all elements from vector
  • Reverse a vector
  • Sort a vector
  • Conversions
  • Convert vector to map
  • Join vector elements to a string
  • Filter even numbers in vector
  • Filter odd numbers in vector
  • Get unique elements of a vector
  • Remove empty strings from vector
  • Sort integer vector in ascending order
  • Sort integer vector in descending order
  • Sort string vector based on length
  • Sort string vector lexicographically
  • Split vector into two equal halves
  • Declare tuple
  • Initialise tuple
  • Swap tuples
  • Unpack tuple elements into variables
  • Concatenate tuples
  • Constructor
  • Copy constructor
  • Virtual destructor
  • Friend class
  • Friend function
  • Inheritance
  • Multiple inheritance
  • Virtual inheritance
  • Function overloading
  • Operator overloading
  • Function overriding
  • C++ Try Catch
  • Math acos()
  • Math acosh()
  • Math asin()
  • Math asinh()
  • Math atan()
  • Math atan2()
  • Math atanh()
  • Math cbrt()
  • Math ceil()
  • Math copysign()
  • Math cosh()
  • Math exp2()
  • Math expm1()
  • Math fabs()
  • Math fdim()
  • Math floor()
  • Math fmax()
  • Math fmin()
  • Math fmod()
  • Math frexp()
  • Math hypot()
  • Math ilogb()
  • Math ldexp()
  • Math llrint()
  • Math llround()
  • Math log10()
  • Math log1p()
  • Math log2()
  • Math logb()
  • Math lrint()
  • Math lround()
  • Math modf()
  • Math nearbyint()
  • Math nextafter()
  • Math nexttoward()
  • Math remainder()
  • Math remquo()
  • Math rint()
  • Math round()
  • Math scalbln()
  • Math scalbn()
  • Math sinh()
  • Math sqrt()
  • Math tanh()
  • Math trunc()
  • Armstrong number
  • Average of three numbers
  • Convert decimal to binary
  • Factorial of a number
  • Factors of a number
  • Fibonacci series
  • Find largest of three numbers
  • Find quotient and remainder
  • HCF/GCD of two numbers
  • Hello World
  • LCM of two numbers
  • Maximum of three numbers
  • Multiply two numbers
  • Sum of two numbers
  • Sum of three numbers
  • Sum of natural numbers
  • Sum of digits in a number
  • Swap two numbers
  • Palindrome number
  • Palindrome string
  • Pattern printing
  • Power of a number
  • Prime number
  • Prime Numbers between two numbers
  • Print number entered by User
  • Reverse a Number
  • Read input from user
  • ❯ C++ Tutorial
  • ❯ C++ Operators
  • ❯ Assignment Operators
  • ❯ Multiplication Assignment

C++ Multiplication Assignment (*=) Operator

In this C++ tutorial, you shall learn about Multiplication Assignment operator, its syntax, and how to use this operator, with examples.

C++ Multiplication Assignment

In C++, Multiplication Assignment Operator is used to find the product of the value (right operand) and this variable (left operand) and assign the result back to this variable (left operand).

The syntax to find the product of a value 2 with variable x and assign the result to x using Multiplication Assignment Operator is

In the following example, we take a variable x with an initial value of 5 , multiply it with a value of 2 and assign the result back to x , using Multiplication Assignment Operator.

In this C++ Tutorial , we learned about Multiplication Assignment Operator in C++, with examples.

Popular Courses by TutorialKart

App developement, web development, online tools.

  • Programming

Rahul Awati

  • Rahul Awati

What is an operator in mathematics and programming?

In mathematics and computer programming , an operator is a character that represents a specific mathematical or logical action or process. For instance, "x" is an arithmetic operator that indicates multiplication, while "&&" is a logical operator representing the logical AND function in programming.

Depending on its type, an operator manipulates an arithmetic or logical value, or operand, in a specific way to generate a specific result. From handling simple arithmetic functions to facilitating the execution of complex algorithms, like security encryption , operators play an important role in the programming world.

Mathematical and logical operators should not be confused with a system operator , or sysop, which refers to a person operating a server or the hardware and software in a computing system or network.

Operators and logic gates

In computer programs, Boolean operators are among the most familiar and commonly used sets of operators. These operators work only with true or false values and include the following:

These operators and variations, such as XOR, are used in logic gates .

Boolean operators can also be used in online search engines , like Google. For example, a user can enter a phrase like "Galileo AND satellite" -- some search engines require the operator be capitalized in order to generate results that provide combined information about both Galileo and satellite.

Types of operators

There are many types of operators used in computing systems and in different programming languages. Based on their function, they can be categorized in six primary ways.

1. Arithmetic operators

Arithmetic operators are used for mathematical calculations. These operators take numerical values as operands and return a single unique numerical value, meaning there can only be one correct answer.

The standard arithmetic operators and their symbols are given below.

+

Addition (a+b)

This operation adds both the operands on either side of the + operator.

-

Subtraction (a-b)

This operation subtracts the right-hand operand from the left.

*

Multiplication (a*b)

This operation multiplies both the operands.

/

Division (a/b)

This operation divides the left-hand operand by the operand on the right.

%

Modulus (a%b)

This operation returns the remainder after dividing the left-hand operand by the right operand.

2. Relational operators

Relational operators are widely used for comparison operators. They enter the picture when certain conditions must be satisfied to return either a true or false value based on the comparison. That's why these operators are also known as conditional operators.

The standard relational operators and their symbols are given below.

==

Equal (a==b)

This operator checks if the values of both operands are equal. If yes, the condition becomes TRUE.

!=

Not equal (a!=b)

This operator checks if the values of both operands are equal. If not, the condition becomes TRUE.

>

Greater than (a>b)

This operator checks if the left operand value is greater than the right. If yes, the condition becomes TRUE.

<

Less than (a<b)

This operator checks if the left operand is less than the value of right. If yes, the condition becomes TRUE.

>=

Greater than or equal (a>=b)

This operator checks if the left operand value is greater than or equal to the value of the right. If either condition is satisfied, the operator returns a TRUE value.

<=

Less than or equal (a<=b)

This operator checks if the left operand value is less than or equal to the value of the right. If either condition is satisfied, the operator returns a TRUE value.

3. Bitwise operators

Bitwise operators are used to manipulate bits and perform bit-level operations . These operators convert integers into binary before performing the required operation and then showing the decimal result.

The standard bitwise operators and their symbols are given below.

&

Bitwise AND (a&b)

This operator copies a bit to the result if it exists in both operands. So, the result is 1 only if both bits are 1.

|

Bitwise OR (a|b)

This operator copies a bit to the result if it exists in either operand. So, the result is 1 if either bit is 1.

^

Bitwise XOR (a^b)

This operator copies a bit to the result if it exists in either operand. So, even if one of the operands is TRUE, the result is TRUE. However, if neither operand is TRUE, the result is FALSE.

~

Bitwise NOT (~a)

This unary operator flips the bits (1 to 0 and 0 to 1).

4. Logical operators

Logical operators play a key role in programming because they enable a system or program to take specific decisions depending on the specific underlying conditions. These operators take Boolean values as input and return the same as output.

The standard logical operators and their symbols are given below.

&&

Logical AND (a&&b)

This operator returns TRUE only if both the operands are TRUE or if both the conditions are satisfied. It not, it returns FALSE.

||

(a||b)

This operator returns TRUE if either operand is TRUE. It also returns TRUE if both the operands are TRUE. If neither operand is true, it returns FALSE.

!

Logical NOT (!a)

This unary operator returns TRUE if the operand is FALSE and vice versa. It is used to reverse the logical state of its (single) operand.

5. Assignment operators

Assignment operators are used to assign values to variables. The left operand is a variable, and the right is a value -- for example, x=3.

The data types of the variable and the value must match; otherwise, the program compiler raises an error, and the operation fails.

The standard assignment operators and their symbols are given below.

=

Assignment (a=b)

This operator assigns the value of the right operand to the left operand (variable).

+=

Add and assign (a+=b)

This operator adds the right operand and the left operand and assigns the result to the left operand.

Logically, the operator means a=a+b.

-=

Subtract and assign (a-=b)

This operator subtracts the right operand from the left operand and assigns the result to the left operand.

Logically, the operator means a=a-b.

*=

Multiply and assign (a*=b)

This operator multiplies the right operand and the left operand and assigns the result to the left operand.

Logically, the operator means a=a*b.

/=

Divide and assign (a/=b)

This operator divides the left operand and the right operand and assigns the result to the left operand.

Logically, the operator means a=a/b.

%=

Modulus and assign (a%=b)

This operator performs the modulus operation on the two operands and assigns the result to the left operand.

Logically, the operator means a=a%b.

6. Increment/decrement operators

The increment/decrement operators are unary operators, meaning they require only one operand and perform an operation on that operand. They sometimes are called monadic operators .

The standard increment/decrement operators and their symbols are given below.

++

Post-increment (a++)

This operator increments the value of the operand by 1 after using its value.

--

Post-decrement (a--)

This operator decrements the value of the operand by 1 after using its value.

++

Pre-increment (++a)

This operator increments the value of the operand by 1 before using its value.

--

Pre-decrement (--a)

This operator decrements the value of the operand by 1 before using its value.

See also: proximity operator , search string , logical negation symbol , character and mathematical symbols .

Continue Reading About operator

  • How to become a good Java programmer without a degree
  • How improving your math skills can help in programming
  • 10 best IT certs for beginners
  • Top 22 cloud computing skills to boost your career in 2022
  • Binary and hexadecimal numbers explained for developers

Related Terms

NBASE-T Ethernet is an IEEE standard and Ethernet-signaling technology that enables existing twisted-pair copper cabling to ...

SD-WAN security refers to the practices, protocols and technologies protecting data and resources transmitted across ...

Net neutrality is the concept of an open, equal internet for everyone, regardless of content consumed or the device, application ...

A proof of concept (PoC) exploit is a nonharmful attack against a computer or network. PoC exploits are not meant to cause harm, ...

A virtual firewall is a firewall device or service that provides network traffic filtering and monitoring for virtual machines (...

Cloud penetration testing is a tactic an organization uses to assess its cloud security effectiveness by attempting to evade its ...

Regulation SCI (Regulation Systems Compliance and Integrity) is a set of rules adopted by the U.S. Securities and Exchange ...

Strategic management is the ongoing planning, monitoring, analysis and assessment of all necessities an organization needs to ...

IT budget is the amount of money spent on an organization's information technology systems and services. It includes compensation...

ADP Mobile Solutions is a self-service mobile app that enables employees to access work records such as pay, schedules, timecards...

Director of employee engagement is one of the job titles for a human resources (HR) manager who is responsible for an ...

Digital HR is the digital transformation of HR services and processes through the use of social, mobile, analytics and cloud (...

A virtual agent -- sometimes called an intelligent virtual agent (IVA) -- is a software program or cloud service that uses ...

A chatbot is a software or computer program that simulates human conversation or "chatter" through text or voice interactions.

Martech (marketing technology) refers to the integration of software tools, platforms, and applications designed to streamline ...

  • Skip to main content
  • Skip to search
  • Skip to select language
  • Sign up for free
  • Português (do Brasil)

Expressions and operators

This chapter documents all the JavaScript language operators, expressions and keywords.

Expressions and operators by category

For an alphabetical listing see the sidebar on the left.

Primary expressions

Basic keywords and general expressions in JavaScript. These expressions have the highest precedence (higher than operators ).

The this keyword refers to a special property of an execution context.

Basic null , boolean, number, and string literals.

Array initializer/literal syntax.

Object initializer/literal syntax.

The function keyword defines a function expression.

The class keyword defines a class expression.

The function* keyword defines a generator function expression.

The async function defines an async function expression.

The async function* keywords define an async generator function expression.

Regular expression literal syntax.

Template literal syntax.

Grouping operator.

Left-hand-side expressions

Left values are the destination of an assignment.

Member operators provide access to a property or method of an object ( object.property and object["property"] ).

The optional chaining operator returns undefined instead of causing an error if a reference is nullish ( null or undefined ).

The new operator creates an instance of a constructor.

In constructors, new.target refers to the constructor that was invoked by new .

An object exposing context-specific metadata to a JavaScript module.

The super keyword calls the parent constructor or allows accessing properties of the parent object.

The import() syntax allows loading a module asynchronously and dynamically into a potentially non-module environment.

Increment and decrement

Postfix/prefix increment and postfix/prefix decrement operators.

Postfix increment operator.

Postfix decrement operator.

Prefix increment operator.

Prefix decrement operator.

Unary operators

A unary operation is an operation with only one operand.

The delete operator deletes a property from an object.

The void operator evaluates an expression and discards its return value.

The typeof operator determines the type of a given object.

The unary plus operator converts its operand to Number type.

The unary negation operator converts its operand to Number type and then negates it.

Bitwise NOT operator.

Logical NOT operator.

Pause and resume an async function and wait for the promise's fulfillment/rejection.

Arithmetic operators

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

Exponentiation operator.

Multiplication operator.

Division operator.

Remainder operator.

Addition operator.

Subtraction operator.

Relational operators

A comparison operator compares its operands and returns a boolean value based on whether the comparison is true.

Less than operator.

Greater than operator.

Less than or equal operator.

Greater than or equal operator.

The instanceof operator determines whether an object is an instance of another object.

The in operator determines whether an object has a given property.

Note: => is not an operator, but the notation for Arrow functions .

Equality operators

The result of evaluating an equality operator is always of type boolean based on whether the comparison is true.

Equality operator.

Inequality operator.

Strict equality operator.

Strict inequality operator.

Bitwise shift operators

Operations to shift all bits of the operand.

Bitwise left shift operator.

Bitwise right shift operator.

Bitwise unsigned right shift operator.

Binary bitwise operators

Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.

Bitwise AND.

Bitwise OR.

Bitwise XOR.

Binary logical operators

Logical operators implement boolean (logical) values and have short-circuiting behavior.

Logical AND.

Logical OR.

Nullish Coalescing Operator.

Conditional (ternary) operator

The conditional operator returns one of two values based on the logical value of the condition.

Assignment operators

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

Assignment operator.

Multiplication assignment.

Division assignment.

Remainder assignment.

Addition assignment.

Subtraction assignment

Left shift assignment.

Right shift assignment.

Unsigned right shift assignment.

Bitwise AND assignment.

Bitwise XOR assignment.

Bitwise OR assignment.

Exponentiation assignment.

Logical AND assignment.

Logical OR assignment.

Nullish coalescing assignment.

Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.

Yield operators

Pause and resume a generator function.

Delegate to another generator function or iterable object.

Spread syntax

Spread syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected. In an object literal, the spread syntax enumerates the properties of an object and adds the key-value pairs to the object being created.

Comma operator

The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.

Specifications

Specification

Browser compatibility

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

  • Operator precedence

Learn Python practically and Get Certified .

Popular Tutorials

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

  • Get Started With Python
  • Your First Python Program
  • Python Comments

Python Fundamentals

  • Python Variables and Literals
  • Python Type Conversion
  • Python Basic Input and Output

Python Operators

Python flow control.

Python if...else Statement

  • Python for Loop
  • Python while Loop
  • Python break and continue
  • Python pass Statement

Python Data types

  • Python Numbers and Mathematics
  • Python List
  • Python Tuple
  • Python String
  • Python Sets
  • Python Dictionary
  • Python Functions
  • Python Function Arguments
  • Python Variable Scope
  • Python Global Keyword
  • Python Recursion
  • Python Modules
  • Python Package
  • Python Main function

Python Files

  • Python Directory and Files Management
  • Python CSV: Read and Write CSV files
  • Reading CSV files in Python
  • Writing CSV files in Python
  • Python Exception Handling
  • Python Exceptions
  • Python Custom Exceptions

Python Object & Class

  • Python Objects and Classes
  • Python Inheritance
  • Python Multiple Inheritance
  • Polymorphism in Python

Python Operator Overloading

Python Advanced Topics

  • List comprehension
  • Python Lambda/Anonymous Function
  • Python Iterators
  • Python Generators
  • Python Namespace and Scope
  • Python Closures
  • Python Decorators
  • Python @property decorator
  • Python RegEx

Python Date and Time

  • Python datetime
  • Python strftime()
  • Python strptime()
  • How to get current date and time in Python?
  • Python Get Current Time
  • Python timestamp to datetime and vice-versa
  • Python time Module
  • Python sleep()

Additional Topic

Precedence and Associativity of Operators in Python

  • Python Keywords and Identifiers
  • Python Asserts
  • Python Json
  • Python *args and **kwargs

Python Tutorials

Python 3 Tutorial

  • Python Strings
  • Python any()

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

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

  • 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.

Operator Operation Example
Addition
Subtraction
Multiplication
Division
Floor Division
Modulo
Power

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.

Operator Name Example
Assignment Operator
Addition Assignment
Subtraction Assignment
Multiplication Assignment
Division Assignment
Remainder Assignment
Exponent Assignment

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 as per our needs.

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.

Operator Meaning Example
Is Equal To gives us
Not Equal To gives us
Greater Than gives us
Less Than gives us
Greater Than or Equal To give us
Less Than or Equal To gives us

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 .

Operator Example Meaning
a b :
only if both the operands are
a b :
if at least one of the operands is
a :
if the operand is and vice-versa.

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)

Operator Meaning Example
Bitwise AND x & y = 0 ( )
Bitwise OR x | y = 14 ( )
Bitwise NOT ~x = -11 ( )
Bitwise XOR x ^ y = 14 ( )
Bitwise right shift x >> 2 = 2 ( )
Bitwise left shift x 0010 1000)

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 at the same memory location.

It's important to note that having two variables with equal values doesn't necessarily mean they are identical.

Operator Meaning Example
if the operands are identical (refer to the same object)
if the operands are not identical (do not refer to the same object)

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. The 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 the presence of a key, not the value.

Operator Meaning Example
if value/variable is in the sequence
if value/variable is in the sequence

Example 5: Membership operators in Python

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

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

  • Precedence and Associativity of operators in Python

Table of Contents

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

Write a function to split the restaurant bill among friends.

  • Take the subtotal of the bill and the number of friends as inputs.
  • Calculate the total bill by adding 20% tax to the subtotal and then divide it by the number of friends.
  • Return the amount each friend has to pay, rounded off to two decimal places.

Video: Operators in Python

Sorry about that.

Related Tutorials

Python Tutorial

  • Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

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

Q&A for work

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

Get early access and see previews of new features.

Implicit type conversion rules in C++ operators

I want to be better about knowing when I should cast. What are the implicit type conversion rules in C++ when adding, multiplying, etc. For example,

et cetera...

Will the expression always be evaluated as the more precise type? Do the rules differ for Java? Please correct me if I have worded this question inaccurately.

Matt Montag's user avatar

  • 20 Keep in mind ^ is XOR. –  GManNickG Apr 6, 2011 at 7:59
  • 19 @int ^ float = compile error :) –  Serge Dundich Apr 6, 2011 at 8:37

9 Answers 9

In C++ operators (for POD types) always act on objects of the same type. Thus if they are not the same one will be promoted to match the other. The type of the result of the operation is the same as operands (after conversion).

Note. The minimum size of operations is int . So short / char are promoted to int before the operation is done.

In all your expressions the int is promoted to a float before the operation is performed. The result of the operation is a float .

Martin York's user avatar

  • 1 "The minimum size of operations is int." - This would be very strange (what about architectures that efficiently support char/short operations?) Is this really in the C++ spec? –  Rafał Dowgird Apr 6, 2011 at 7:59
  • 5 @Rafal: Yes. int is supposed to be the most efficient integer type for operation on a particular platform. char must always be 1 but short can be the same size as int. –  Martin York Apr 6, 2011 at 8:08
  • 2 @Rafał: yes, it is very strange and it is is in the standard. In a lot of cases, the architecture you describe could use its super-efficient char type. If the value of char + char is assigned to a char , then it can just do the arithmetic in char and for example wrap around. But if the result is assigned to int then it has to do the arithmetic in a type large enough to get the correct result when it's more than CHAR_MAX . –  Steve Jessop Apr 6, 2011 at 8:27
  • 8 I just want to emphasize the fact that int gets promoted to unsigned int !!! I've struggled with bugs for days because I was under the impression that both would be promoted to int or long so that a possible negative result would not cause an underflow/wrap-around. –  nitsas Apr 24, 2013 at 12:53
  • 15 Example of the problem " int gets promoted to unsigned int ": ((int) 4) - ((unsigned int) 5) will result in 4294967295 for 32 bit ints and 32 bit unsigned ints. –  nitsas Apr 24, 2013 at 13:15

Arithmetic operations involving float results in float .

For more detail answer. Look at what the section §5/9 from the C++ Standard says

Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result . This pattern is called the usual arithmetic conversions, which are defined as follows: — If either operand is of type long double, the other shall be converted to long double. — Otherwise, if either operand is double, the other shall be converted to double. — Otherwise, if either operand is float, the other shall be converted to float. — Otherwise, the integral promotions (4.5) shall be performed on both operands.54) — Then, if either operand is unsigned long the other shall be converted to unsigned long. — Otherwise, if one operand is a long int and the other unsigned int, then if a long int can represent all the values of an unsigned int, the unsigned int shall be converted to a long int; otherwise both operands shall be converted to unsigned long int. — Otherwise, if either operand is long, the other shall be converted to long. — Otherwise, if either operand is unsigned, the other shall be converted to unsigned. [Note: otherwise, the only remaining case is that both operands are int ]

Community's user avatar

  • 4 ...so long as the other type is neither double nor long double . –  CB Bailey Apr 6, 2011 at 7:53
  • 1 @Charles: Correct. I quoted the relevant section from the Standard to clarify further. –  Sarfaraz Nawaz Apr 6, 2011 at 7:58
  • So can an integer always be converted to float without any data loss? (e.g. by zero-ing the exponent and using everything for the mantissa) ? –  Marco A. Feb 25, 2014 at 13:25
  • 1 This answer is out-of-date. Suggest update. In particular, long long and unsigned long not addressed right here. –  chux - Reinstate Monica Jan 7, 2016 at 18:39
  • @MarcoA. a 32-bit float doesn't have enough bits in the mantissa (24 bits for IEEE-754 ) for a 32-bit int , so there might be some data loss. A 64-bit double should be just fine. –  Mark Ransom Jun 2, 2020 at 13:55

Since the other answers don't talk about the rules in C++11 here's one. From C++11 standard (draft n3337) §5/9 (emphasized the difference):

This pattern is called the usual arithmetic conversions , which are defined as follows: — If either operand is of scoped enumeration type, no conversions are performed; if the other operand does not have the same type, the expression is ill-formed. — If either operand is of type long double, the other shall be converted to long double. — Otherwise, if either operand is double, the other shall be converted to double. — Otherwise, if either operand is float, the other shall be converted to float. — Otherwise, the integral promotions shall be performed on both operands. Then the following rules shall be applied to the promoted operands: — If both operands have the same type, no further conversion is needed. — Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank shall be converted to the type of the operand with greater rank. — Otherwise, if the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type shall be converted to the type of the operand with unsigned integer type. — Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, the operand with unsigned integer type shall be converted to the type of the operand with signed integer type. — Otherwise, both operands shall be converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

See here for a list that's frequently updated.

legends2k's user avatar

  • 2 These rules were the same in all versions of C++, except for scoped enumerations which were added in C++11 of course –  M.M Sep 4, 2019 at 22:43

This answer is directed in large part at a comment made by @RafałDowgird:

"The minimum size of operations is int." - This would be very strange (what about architectures that efficiently support char/short operations?) Is this really in the C++ spec?

Keep in mind that the C++ standard has the all-important "as-if" rule. See section 1.8: Program Execution:

3) This provision is sometimes called the "as-if" rule, because an implementation is free to disregard any requirement of the Standard as long as the result is as if the requirement had been obeyed, as far as can be determined from the observable behavior of the program.

The compiler cannot set an int to be 8 bits in size, even if it were the fastest, since the standard mandates a 16-bit minimum int .

Therefore, in the case of a theoretical computer with super-fast 8-bit operations, the implicit promotion to int for arithmetic could matter. However, for many operations, you cannot tell if the compiler actually did the operations in the precision of an int and then converted to a char to store in your variable, or if the operations were done in char all along.

For example, consider unsigned char = unsigned char + unsigned char + unsigned char , where addition would overflow (let's assume a value of 200 for each). If you promoted to int , you would get 600, which would then be implicitly down cast into an unsigned char , which would wrap modulo 256, thus giving a final result of 88. If you did no such promotions,you'd have to wrap between the first two additions, which would reduce the problem from 200 + 200 + 200 to 144 + 200 , which is 344, which reduces to 88. In other words, the program does not know the difference, so the compiler is free to ignore the mandate to perform intermediate operations in int if the operands have a lower ranking than int .

This is true in general of addition, subtraction, and multiplication. It is not true in general for division or modulus.

David Stone's user avatar

If you exclude the unsigned types, there is an ordered hierarchy: signed char, short, int, long, long long, float, double, long double. First, anything coming before int in the above will be converted to int. Then, in a binary operation, the lower ranked type will be converted to the higher, and the results will be the type of the higher. (You'll note that, from the hierarchy, anytime a floating point and an integral type are involved, the integral type will be converted to the floating point type.)

Unsigned complicates things a bit: it perturbs the ranking, and parts of the ranking become implementation defined. Because of this, it's best to not mix signed and unsigned in the same expression. (Most C++ experts seem to avoid unsigned unless bitwise operations are involved. That is, at least, what Stroustrup recommends.)

James Kanze's user avatar

  • 3 Stroustrup can recommend what he likes, but using a sign-able int for a number that never needs to be negative is a complete waste of a full 50% of the available range. I'm certainly no Stroustrup, but I use unsigned by default and signed only when I have a reason. –  underscore_d Dec 18, 2015 at 1:08
  • 2 That's all well and good, underscore_d, until the day when you have to subtract. The primary problem with unsigned numbers in C++ is that when you perform subtraction, they stay unsigned. So suppose you write a function to see if a std::vector is in order. You might write bool in_order(vector<T> vec) { for ( int i = 0; i < size() - 1; ++i) { if (vec[i + 1] < vec[i]) return false; } return true; and then you'd be annoyed to find that it crashes for empty vectors because size() - 1 returns 18446744073709551615. –  jorgbrown Feb 4, 2019 at 5:53

My solution to the problem got WA(wrong answer), then i changed one of int to long long int and it gave AC(accept) . Previously, I was trying to do long long int += int * int , and after I rectify it to long long int += long long int * int . Googling I came up with,

1. Arithmetic Conversions

Conditions for Type Conversion:

Conditions Met ---> Conversion

Either operand is of type long double . ---> Other operand is converted to type long double .

Preceding condition not met and either operand is of type double . ---> Other operand is converted to type double .

Preceding conditions not met and either operand is of type float . ---> Other operand is converted to type float .

Preceding conditions not met (none of the operands are of floating types). ---> Integral promotions are performed on the operands as follows:

  • If either operand is of type unsigned long , the other operand is converted to type unsigned long .
  • If preceding condition not met, and if either operand is of type long and the other of type unsigned int , both operands are converted to type unsigned long .
  • If the preceding two conditions are not met, and if either operand is of type long , t he other operand is converted to type long .
  • If the preceding three conditions are not met, and if either operand is of type unsigned int , the other operand is converted to type unsigned int .
  • If none of the preceding conditions are met, both operands are converted to type int .

Your Answer

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

Sign up or log in

Post as a guest.

Required, but never shown

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

Not the answer you're looking for? Browse other questions tagged c++ casting implicit or ask your own question .

  • Featured on Meta
  • The 2024 Developer Survey Is Live
  • The return of Staging Ground to Stack Overflow
  • The [tax] tag is being burninated
  • Policy: Generative AI (e.g., ChatGPT) is banned

Hot Network Questions

  • How does the Cube of Force interact with teleportation?
  • Markov Chains with Changing Number of States
  • My players think they found a loophole that gives them infinite poison and XP. How can I add the proper challenges to slow them down?
  • Projective space as Grassmannian
  • How to make Tikz-cd diagram symmetric
  • Converting NEMA 10-30 to 14-30 using ground from adjacent 15 amp receptacle
  • Why is killing even evil brahmins categorized as 'brahma hatya'?
  • Have I ruined my AC by running it with the outside cover on?
  • How to make Bash remove quotes after parameter expansion?
  • How do you keep the horror spooky when your players are a bunch of goofballs?
  • What scientific evidence there is that keeping cooked meat at room temperature is unsafe past two hours?
  • the angular orbital velocity of satellite in circle orbit is constant?
  • Replacement the UPS APC Smart-UPS SRT 10000 battery while it's powered on?
  • A man is kidnapped by his future descendants and isolated his whole life to prevent a bad thing; they accidentally undo their own births
  • Science fiction book about a world where bioengineered animals are used for common functions
  • Can I paraphrase an conference paper I wrote in my dissertation?
  • Are there any jobs that are forbidden by law to convicted felons?
  • Do meanings of statements exist?
  • NES Emulator in C
  • Missing items in my list of abbreviations
  • Do we know how the SpaceX Starship stack handles engine shutdowns?
  • I'm looking for a series where there was a civilization in the Mediterranean basin, which got destroyed by the Atlantic breaking in
  • Is the barrier to entry for mathematics research increasing, and is it at risk of becoming less accessible in the future?
  • An application of the (100/e)% rule applied to postdocs: moving on from an academic career, perhaps

multiplying assignment operator c

  • Python Basics
  • Interview Questions
  • Python Quiz
  • Popular Packages
  • Python Projects
  • Practice Python
  • AI With Python
  • Learn Python3
  • Python Automation
  • Python Web Dev
  • DSA with Python
  • Python OOPs
  • Dictionaries

Python Operators

Precedence and associativity of operators in python.

  • Python Arithmetic Operators
  • Difference between / vs. // operator in Python
  • Python - Star or Asterisk operator ( * )
  • What does the Double Star operator mean in Python?
  • Division Operators in Python
  • Modulo operator (%) in Python
  • Python Logical Operators
  • Python OR Operator
  • Difference between 'and' and '&' in Python
  • not Operator in Python | Boolean Logic

Ternary Operator in Python

  • Python Bitwise Operators

Python Assignment Operators

Assignment operators in python.

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

Python Relational Operators

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

In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. 

  • OPERATORS: These are the special symbols. Eg- + , * , /, etc.
  • OPERAND: It is the value on which the operator is applied.

Types of Operators in Python

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Identity Operators and Membership Operators

Python Operators

Arithmetic Operators in Python

Python Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication , and division .

In Python 3.x the result of division is a floating-point while in Python 2.x division of 2 integers was an integer. To obtain an integer result in Python 3.x floored (// integer) is used.

OperatorDescriptionSyntax
+Addition: adds two operandsx + y
Subtraction: subtracts two operandsx – y
*Multiplication: multiplies two operandsx * y
/Division (float): divides the first operand by the secondx / y
//Division (floor): divides the first operand by the secondx // y
%Modulus: returns the remainder when the first operand is divided by the secondx % y
**Power: Returns first raised to power secondx ** y

Example of Arithmetic Operators in Python

Division operators.

In Python programming language Division Operators allow you to divide two numbers and return a quotient, i.e., the first number or number at the left is divided by the second number or number at the right and returns the quotient. 

There are two types of division operators: 

Float division

  • Floor division

The quotient returned by this operator is always a float number, no matter if two numbers are integers. For example:

Example: The code performs division operations and prints the results. It demonstrates that both integer and floating-point divisions return accurate results. For example, ’10/2′ results in ‘5.0’ , and ‘-10/2’ results in ‘-5.0’ .

Integer division( Floor division)

The quotient returned by this operator is dependent on the argument being passed. If any of the numbers is float, it returns output in float. It is also known as Floor division because, if any number is negative, then the output will be floored. For example:

Example: The code demonstrates integer (floor) division operations using the // in Python operators . It provides results as follows: ’10//3′ equals ‘3’ , ‘-5//2’ equals ‘-3’ , ‘ 5.0//2′ equals ‘2.0’ , and ‘-5.0//2’ equals ‘-3.0’ . Integer division returns the largest integer less than or equal to the division result.

Precedence of Arithmetic Operators in Python

The precedence of Arithmetic Operators in Python is as follows:

  • P – Parentheses
  • E – Exponentiation
  • M – Multiplication (Multiplication and division have the same precedence)
  • D – Division
  • A – Addition (Addition and subtraction have the same precedence)
  • S – Subtraction

The modulus of Python operators helps us extract the last digit/s of a number. For example:

  • x % 10 -> yields the last digit
  • x % 100 -> yield last two digits

Arithmetic Operators With Addition, Subtraction, Multiplication, Modulo and Power

Here is an example showing how different Arithmetic Operators in Python work:

Example: The code performs basic arithmetic operations with the values of ‘a’ and ‘b’ . It adds (‘+’) , subtracts (‘-‘) , multiplies (‘*’) , computes the remainder (‘%’) , and raises a to the power of ‘b (**)’ . The results of these operations are printed.

Note: Refer to Differences between / and // for some interesting facts about these two Python operators.

Comparison of Python Operators

In Python Comparison of Relational operators compares the values. It either returns True or False according to the condition.

OperatorDescriptionSyntax
>Greater than: True if the left operand is greater than the rightx > y
<Less than: True if the left operand is less than the rightx < y
==Equal to: True if both operands are equalx == y
!=Not equal to – True if operands are not equalx != y
>=Greater than or equal to True if the left operand is greater than or equal to the rightx >= y
<=Less than or equal to True if the left operand is less than or equal to the rightx <= y

= is an assignment operator and == comparison operator.

Precedence of Comparison Operators in Python

In Python, the comparison operators have lower precedence than the arithmetic operators. All the operators within comparison operators have the same precedence order.

Example of Comparison Operators in Python

Let’s see an example of Comparison Operators in Python.

Example: The code compares the values of ‘a’ and ‘b’ using various comparison Python operators and prints the results. It checks if ‘a’ is greater than, less than, equal to, not equal to, greater than, or equal to, and less than or equal to ‘b’ .

Logical Operators in Python

Python Logical operators perform Logical AND , Logical OR , and Logical NOT operations. It is used to combine conditional statements.

OperatorDescriptionSyntax
andLogical AND: True if both the operands are truex and y
orLogical OR: True if either of the operands is true x or y
notLogical NOT: True if the operand is false not x

Precedence of Logical Operators in Python

The precedence of Logical Operators in Python is as follows:

  • Logical not
  • logical and

Example of Logical Operators in Python

The following code shows how to implement Logical Operators in Python:

Example: The code performs logical operations with Boolean values. It checks if both ‘a’ and ‘b’ are true ( ‘and’ ), if at least one of them is true ( ‘or’ ), and negates the value of ‘a’ using ‘not’ . The results are printed accordingly.

Bitwise Operators in Python

Python Bitwise operators act on bits and perform bit-by-bit operations. These are used to operate on binary numbers.

OperatorDescriptionSyntax
&Bitwise ANDx & y
|Bitwise ORx | y
~Bitwise NOT~x
^Bitwise XORx ^ y
>>Bitwise right shiftx>>
<<Bitwise left shiftx<<

Precedence of Bitwise Operators in Python

The precedence of Bitwise Operators in Python is as follows:

  • Bitwise NOT
  • Bitwise Shift
  • Bitwise AND
  • Bitwise XOR

Here is an example showing how Bitwise Operators in Python work:

Example: The code demonstrates various bitwise operations with the values of ‘a’ and ‘b’ . It performs bitwise AND (&) , OR (|) , NOT (~) , XOR (^) , right shift (>>) , and left shift (<<) operations and prints the results. These operations manipulate the binary representations of the numbers.

Python Assignment operators are used to assign values to the variables.

OperatorDescriptionSyntax
=Assign the value of the right side of the expression to the left side operand x = y + z
+=Add AND: Add right-side operand with left-side operand and then assign to left operanda+=b     a=a+b
-=Subtract AND: Subtract right operand from left operand and then assign to left operanda-=b     a=a-b
*=Multiply AND: Multiply right operand with left operand and then assign to left operanda*=b     a=a*b
/=Divide AND: Divide left operand with right operand and then assign to left operanda/=b     a=a/b
%=Modulus AND: Takes modulus using left and right operands and assign the result to left operanda%=b     a=a%b
//=Divide(floor) AND: Divide left operand with right operand and then assign the value(floor) to left operanda//=b     a=a//b
**=Exponent AND: Calculate exponent(raise power) value using operands and assign value to left operanda**=b     a=a**b
&=Performs Bitwise AND on operands and assign value to left operanda&=b     a=a&b
|=Performs Bitwise OR on operands and assign value to left operanda|=b     a=a|b
^=Performs Bitwise xOR on operands and assign value to left operanda^=b     a=a^b
>>=Performs Bitwise right shift on operands and assign value to left operanda>>=b     a=a>>b
<<=Performs Bitwise left shift on operands and assign value to left operanda <<= b     a= a << b

Let’s see an example of Assignment Operators in Python.

Example: The code starts with ‘a’ and ‘b’ both having the value 10. It then performs a series of operations: addition, subtraction, multiplication, and a left shift operation on ‘b’ . The results of each operation are printed, showing the impact of these operations on the value of ‘b’ .

Identity Operators in Python

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

Example Identity Operators in Python

Let’s see an example of Identity Operators in Python.

Example: The code uses identity operators to compare variables in Python. It checks if ‘a’ is not the same object as ‘b’ (which is true because they have different values) and if ‘a’ is the same object as ‘c’ (which is true because ‘c’ was assigned the value of ‘a’ ).

Membership Operators in Python

In Python, in and not in are the membership operators that are used to test whether a value or variable is in a sequence.

Examples of Membership Operators in Python

The following code shows how to implement Membership Operators in Python:

Example: The code checks for the presence of values ‘x’ and ‘y’ in the list. It prints whether or not each value is present in the list. ‘x’ is not in the list, and ‘y’ is present, as indicated by the printed messages. The code uses the ‘in’ and ‘not in’ Python operators to perform these checks.

in Python, Ternary operators also known as conditional expressions are operators that evaluate something based on a condition being true or false. It was added to Python in version 2.5. 

It simply allows testing a condition in a single line replacing the multiline if-else making the code compact.

Syntax :   [on_true] if [expression] else [on_false] 

Examples of Ternary Operator in Python

The code assigns values to variables ‘a’ and ‘b’ (10 and 20, respectively). It then uses a conditional assignment to determine the smaller of the two values and assigns it to the variable ‘min’ . Finally, it prints the value of ‘min’ , which is 10 in this case.

In Python, Operator precedence and associativity determine the priorities of the operator.

Operator Precedence in Python

This is used in an expression with more than one operator with different precedence to determine which operation to perform first.

Let’s see an example of how Operator Precedence in Python works:

Example: The code first calculates and prints the value of the expression 10 + 20 * 30 , which is 610. Then, it checks a condition based on the values of the ‘name’ and ‘age’ variables. Since the name is “ Alex” and the condition is satisfied using the or operator, it prints “Hello! Welcome.”

Operator Associativity in Python

If an expression contains two or more operators with the same precedence then Operator Associativity is used to determine. It can either be Left to Right or from Right to Left.

The following code shows how Operator Associativity in Python works:

Example: The code showcases various mathematical operations. It calculates and prints the results of division and multiplication, addition and subtraction, subtraction within parentheses, and exponentiation. The code illustrates different mathematical calculations and their outcomes.

To try your knowledge of Python Operators, you can take out the quiz on Operators in Python . 

Python Operator Exercise Questions

Below are two Exercise Questions on Python Operators. We have covered arithmetic operators and comparison operators in these exercise questions. For more exercises on Python Operators visit the page mentioned below.

Q1. Code to implement basic arithmetic operations on integers

Q2. Code to implement Comparison operations on integers

Explore more Exercises: Practice Exercise on Operators in Python

Please Login to comment...

Similar reads.

  • python-basics
  • Python-Operators

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

IMAGES

  1. Assignment Operators in C

    multiplying assignment operator c

  2. PPT

    multiplying assignment operator c

  3. [100% Working Code]

    multiplying assignment operator c

  4. C programming +=

    multiplying assignment operator c

  5. C# Assignment Operator

    multiplying assignment operator c

  6. Assignment Operators in C Example

    multiplying assignment operator c

VIDEO

  1. Assignment Operator in C Programming

  2. 14. Assignment Operator

  3. C program to multiply two numbers using plus operator

  4. Assignment Operators in C Programming

  5. Operator in C

  6. 66. C Program To Multiply Number By 4 Using Bitwise Operator

COMMENTS

  1. Assignment operators

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

  2. Assignment Operators in Programming

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

  3. Assignment Operators in C

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

  4. c

    sample1 = 0; sample2 = 0; specially if you are initializing to a non-zero value. Because, the multiple assignment translates to: sample2 = 0; sample1 = sample2; So instead of 2 initializations you do only one and one copy. The speed up (if any) will be tiny but in embedded case every tiny bit counts!

  5. Assignment operators

    The built-in assignment operators return the value of the object specified by the left operand after the assignment (and the arithmetic/logical operation in the case of compound assignment operators). The resultant type is the type of the left operand. The result of an assignment expression is always an l-value.

  6. Operators in C

    An operator is a symbol that operates on a value or a variable. For example: + is an operator to perform addition. In this tutorial, you will learn about different C operators such as arithmetic, increment, assignment, relational, logical, etc. with the help of examples.

  7. C Programming Assignment Operators

    Assignment Operators in C are used to assign values to the variables. They come under the category of binary operators as they require two operands to operate upon. The left side operand is called a variable and the right side operand is the value. The value on the right side of the "=" is assigned to the variable on the left side of "=".

  8. C Assignment Operators

    Code language:C++(cpp) The = assignment operator is called a simple assignment operator. It assigns the value of the left operand to the right operand. Besides the simple assignment operator, C supports compound assignment operators. A compound assignment operator performs the operation specified by the additional operator and then assigns the ...

  9. C Assignment Operators

    The assignment operators in C can both transform and assign values in a single operation. C provides the following assignment operators: | =. In assignment, the type of the right-hand value is converted to the type of the left-hand value, and the value is stored in the left operand after the assignment has taken place.

  10. 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. This operator first adds the current value of the variable on left to the value on the right and ...

  11. Assignment Operators in C with Examples

    C supports following Assignment operators: 1. Simple Assignment = Operator Example. This is one of the simplest assignment operator, it simply assigns the right side value to the left side operand. #include <stdio.h> int main () { int n; //integer variable char ch; //character variable float f; //float variable // Simple assignment operator to ...

  12. Learn C: Operators Cheatsheet

    C can assign values to variables and perform basic mathematical operations using shorthand operators: Assignment: = ... Multiplication then assignment: *= Division then assignment: /= Modulo then assignment: %= Comparing values in C. C can compare two values and/or variables against each other to return true or false. The operators are as follows:

  13. Multiplication-Assign Operator

    The return value is an rvalue in C : the value of the left operand after assignment. in C++, the return value is an lvalue : the (now assigned) left operand itself. The multiplication-assignment operator behaves exactly like the assignment operator except that it performs an additional multiplication.

  14. Assignment Operators In C++

    In C++, the addition assignment operator (+=) combines the addition operation with the variable assignment allowing you to increment the value of variable by a specified expression in a concise and efficient way. Syntax. variable += value; This above expression is equivalent to the expression: variable = variable + value; Example.

  15. Demystifying Assignment Operators in C Programming

    Assignment operators are fundamental in C programming, as they allow you to assign values and manipulate variables efficiently. In this article, we'll explore the basics of C programming's assignment operators: = (Assignment), += (Add and assign), -= (Subtract and assign), *= (Multiply and assign), /= (Divide and assign), and %= (Modulus and assign).

  16. C++ Multiplication Assignment (*=) Operator

    In C++, Multiplication Assignment Operator is used to find the product of the value (right operand) and this variable (left operand) and assign the result back to this variable (left operand). The syntax to find the product of a value 2 with variable x and assign the result to x using Multiplication Assignment Operator is. x *= 2.

  17. simple c++: How to overload the multiplication operator so that float

    It works - the operator is scoped to the object to which it is declared. In the first case, the subtlety is that the functions are not member functions of MyClass, they are at global scope - and argument-dependent lookup will find them even if the first argument is a float.

  18. What is an operator in programming?

    In mathematics and computer programming, an operator is a character that represents a specific mathematical or logical action or process. For instance, "x" is an arithmetic operator that indicates multiplication, while "&&" is a logical operator representing the logical AND function in programming. Depending on its type, an operator manipulates ...

  19. Expressions and operators

    Basic keywords and general expressions in JavaScript. These expressions have the highest precedence (higher than operators ). The this keyword refers to a special property of an execution context. Basic null, boolean, number, and string literals. Array initializer/literal syntax. Object initializer/literal syntax.

  20. What Are the Basic Rules and Idioms for Operator Overloading in C++?

    Rules and Idioms for Operator Overloading in C++. Following are the fundamental rules and idioms that should be followed when overloading operators in C++: 1. Overload only Built-in Operators. In C++, only existing built-in operators can be overloaded. We cannot create a new operator or rename existing ones, hence if any operator is not present ...

  21. Python Operators (With Examples)

    Example 2: Assignment Operators # assign 10 to a a = 10 # assign 5 to b b = 5 # assign the sum of a and b to a a += b # a = a + b print(a) # Output: 15. Here, we have used the += operator to assign the sum of a and b to a. Similarly, we can use any other assignment operators as per our needs.

  22. operators

    These both exhibit undefined behaviour in both C++03 and C++11. In C++11 terminology, you can't have two unsequenced modifications of the same scalar or a modification and a value computation using the same scalar, otherwise you have undefined behaviour. x = x * x++;

  23. Implicit type conversion rules in C++ operators

    An rvalue of type float can be converted to an rvalue of type double. The value is unchanged. This conversion is called floating point promotion. Therefore, all conversions involving float - the result is float. Only the one involving both int - the result is int : int / int = int. answered Apr 6, 2011 at 7:53.

  24. Python Operators

    Assignment Operators in Python. Let's see an example of Assignment Operators in Python. Example: The code starts with 'a' and 'b' both having the value 10. It then performs a series of operations: addition, subtraction, multiplication, and a left shift operation on 'b'.