C Functions

C structures, c reference, c operators.

Operators are used to perform operations on variables and values.

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

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

C divides the operators into the following groups:

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

Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

Operator Name Description Example Try it
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from another x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division remainder x % y
++ Increment Increases the value of a variable by 1 ++x
-- Decrement Decreases the value of a variable by 1 --x

Assignment Operators

Assignment operators are used to assign values to variables.

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

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

A list of all assignment operators:

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

Comparison Operators

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

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

Comparison operators are used to compare two values.

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

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

A list of all comparison operators:

Operator Name Example Description Try it
== Equal to x == y Returns 1 if the values are equal
!= Not equal x != y Returns 1 if the values are not equal
> Greater than x > y Returns 1 if the first value is greater than the second value
< Less than x < y Returns 1 if the first value is less than the second value
>= Greater than or equal to x >= y Returns 1 if the first value is greater than, or equal to, the second value
<= Less than or equal to x <= y Returns 1 if the first value is less than, or equal to, the second value

Logical Operators

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

Logical operators are used to determine the logic between variables or values, by combining multiple conditions:

Operator Name Example Description Try it
&&  AND x < 5 &&  x < 10 Returns 1 if both statements are true
||  OR x < 5 || x < 4 Returns 1 if one of the statements is true
! NOT !(x < 5 && x < 10) Reverse the result, returns 0 if the result is 1

C Exercises

Test yourself with exercises.

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

Start the Exercise

Get Certified

COLOR PICKER

colorpicker

Contact Sales

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

Report Error

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

Top Tutorials

Top references, top examples, get certified.

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.

CProgramming Tutorial

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

Assignment Operators in C

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

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

In addition, C has several augmented assignment operators.

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

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

Simple Assignment Operator (=)

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

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

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

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

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

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

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

Augmented Assignment Operators

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

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

Run the code and check its output −

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

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

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

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

Learn C practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn c interactively.

  • Print Pyramids and Patterns
  • Make a Simple Calculator Using switch...case
  • Display Factors of a Number
  • Display Armstrong Number Between Two Intervals
  • Check Armstrong Number
  • Display Prime Numbers Between Two Intervals
  • Check Whether a Number is Prime or Not
  • Check Whether a Number is Palindrome or Not

C Tutorials

Calculate the Sum of Natural Numbers

Print an Integer (Entered by the User)

Check Whether a Number is Positive or Negative

Find GCD of two Numbers

  • Calculate Average Using Arrays

C Program to Generate Multiplication Table

To understand this example, you should have the knowledge of the following C programming topics:

  • C Programming Operators

The program below takes an integer input from the user and generates the multiplication tables up to 10.

Multiplication Table Up to 10

Here, the user input is stored in the int variable n . Then, we use a for loop to print the multiplication table up to 10.

The loop runs from i = 1 to i = 10 . In each iteration of the loop, n * i is printed.

Here's a little modification of the above program to generate the multiplication table up to a range (where range is also a positive integer entered by the user).

Multiplication Table Up to a range

Here, we have used a do...while loop to prompt the user for a positive range.

If the value of range is negative, the loop iterates again to ask the user to enter a positive number. Once a positive range has been entered, we print the multiplication table.

Sorry about that.

Our premium learning platform, created with over a decade of experience and thousands of feedbacks .

Learn and improve your coding skills like never before.

  • Interactive Courses
  • Certificates
  • 2000+ Challenges

Related Examples

cppreference.com

Assignment operators.

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


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

expression
pointer
specifier

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

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

Assignment operators modify the value of the object.

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

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

[ edit ] Definitions

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

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

(since C++11)

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

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

[ edit ] Assignment operator syntax

The assignment expressions have the form

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

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

(since C++11)

[ edit ] Built-in simple assignment operator

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

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

[ edit ] Assignment from an expression

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

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

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

(since C++20)

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

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

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

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

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

operator=(T&, T);

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

operator=(A1&, A2);

[ edit ] Built-in compound assignment operator

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

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

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

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

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

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

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

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

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

[ edit ] Example

Possible output:

[ edit ] Defect reports

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

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

[ edit ] See also

Operator precedence

Operator overloading

Common operators

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

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

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

!a
a && b
a || b

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

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

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

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

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

Powered by MediaWiki

6.1 — Operator precedence and associativity

Prec/AssOperatorDescriptionPattern
1 L->R::
::
Global scope (unary)
Namespace scope (binary)
::name
class_name::member_name
2 L->R()
()
type()
type{}
[]
.
->
++
––
typeid
const_cast
dynamic_cast
reinterpret_cast
static_cast
sizeof…
noexcept
alignof
Parentheses
Function call
Functional cast
List init temporary object (C++11)
Array subscript
Member access from object
Member access from object ptr
Post-increment
Post-decrement
Run-time type information
Cast away const
Run-time type-checked cast
Cast one type to another
Compile-time type-checked cast
Get parameter pack size
Compile-time exception check
Get type alignment
(expression)
function_name(arguments)
type(expression)
type{expression}
pointer[expression]
object.member_name
object_pointer->member_name
lvalue++
lvalue––
typeid(type) or typeid(expression)
const_cast<type>(expression)
dynamic_cast<type>(expression)
reinterpret_cast<type>(expression)
static_cast<type>(expression)
sizeof…(expression)
noexcept(expression)
alignof(type)
3 R->L+
-
++
––
!
not
~
(type)
sizeof
co_await
&
*
new
new[]
delete
delete[]
Unary plus
Unary minus
Pre-increment
Pre-decrement
Logical NOT
Logical NOT
Bitwise NOT
C-style cast
Size in bytes
Await asynchronous call
Address of
Dereference
Dynamic memory allocation
Dynamic array allocation
Dynamic memory deletion
Dynamic array deletion
+expression
-expression
++lvalue
––lvalue
!expression
not expression
~expression
(new_type)expression
sizeof(type) or sizeof(expression)
co_await expression (C++20)
&lvalue
*expression
new type
new type[expression]
delete pointer
delete[] pointer
4 L->R->*
.*
Member pointer selector
Member object selector
object_pointer->*pointer_to_member
object.*pointer_to_member
5 L->R*
/
%
Multiplication
Division
Remainder
expression * expression
expression / expression
expression % expression
6 L->R+
-
Addition
Subtraction
expression + expression
expression - expression
7 L->R<<
>>
Bitwise shift left / Insertion
Bitwise shift right / Extraction
expression << expression
expression >> expression
8 L->R<=>Three-way comparison (C++20)expression <=> expression
9 L->R<
<=
>
>=
Comparison less than
Comparison less than or equals
Comparison greater than
Comparison greater than or equals
expression < expression
expression <= expression
expression > expression
expression >= expression
10 L->R==
!=
Equality
Inequality
expression == expression
expression != expression
11 L->R&Bitwise ANDexpression & expression
12 L->R^Bitwise XORexpression ^ expression
13 L->R|Bitwise ORexpression | expression
14 L->R&&
and
Logical AND
Logical AND
expression && expression
expression and expression

15 L->R||
or
Logical OR
Logical OR
expression || expression
expression or expression
16 R->Lthrow
co_yield
?:
=
*=
/=
%=
+=
-=
<<=
>>=
&=
|=
^=
Throw expression
Yield expression (C++20)
Conditional
Assignment
Multiplication assignment
Division assignment
Remainder assignment
Addition assignment
Subtraction assignment
Bitwise shift left assignment
Bitwise shift right assignment
Bitwise AND assignment
Bitwise OR assignment
Bitwise XOR assignment
throw expression
co_yield expression
expression ? expression : expression
lvalue = expression
lvalue *= expression
lvalue /= expression
lvalue %= expression
lvalue += expression
lvalue -= expression
lvalue <<= expression
lvalue >>= expression
lvalue &= expression
lvalue |= expression
lvalue ^= expression
17 L->R,Comma operatorexpression, expression

Best practice

Value computation (of operations)

We know from the precedence and associativity rules above that this expression will be grouped as if we had typed:

Sample problem: x = 2 + 3 % 4

Binary operator has higher precedence than operator or operator , so it gets evaluated first:

x = 2 + (3 % 4)

Binary operator has a higher precedence than operator , so it gets evaluated next:

Final answer: x = (2 + (3 % 4))

We now no longer need the table above to understand how this expression will evaluate.

  • C++ Data Types
  • C++ Input/Output
  • C++ Pointers
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management

Assignment Operators In C++

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

The right-hand side value will be assigned to the variable on the left-hand side. The variable and the value should be of the same data type.

The value can be a literal or another variable of the same data type.

 

Compound Assignment Operators

In C++, the assignment operator can be combined into a single operator with some other operators to perform a combination of two operations in one single statement. These operators are called Compound Assignment Operators. There are 10 compound assignment operators in C++:

  • Addition Assignment Operator ( += )
  • Subtraction Assignment Operator ( -= )
  • Multiplication Assignment Operator ( *= )
  • Division Assignment Operator ( /= )
  • Modulus Assignment Operator ( %= )
  • Bitwise AND Assignment Operator ( &= )
  • Bitwise OR Assignment Operator ( |= )
  • Bitwise XOR Assignment Operator ( ^= )
  • Left Shift Assignment Operator ( <<= )
  • Right Shift Assignment Operator ( >>= )

Lets see each of them in detail.

1. Addition Assignment Operator (+=)

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.

This above expression is equivalent to the expression:

   

2. Subtraction Assignment Operator (-=)

The subtraction assignment operator (-=) in C++ enables you to update the value of the variable by subtracting another value from it. This operator is especially useful when you need to perform subtraction and store the result back in the same variable.

   

3. Multiplication Assignment Operator (*=)

In C++, the multiplication assignment operator (*=) is used to update the value of the variable by multiplying it with another value.

 

4. Division Assignment Operator (/=)

The division assignment operator divides the variable on the left by the value on the right and assigns the result to the variable on the left.

       

5. Modulus Assignment Operator (%=)

The modulus assignment operator calculates the remainder when the variable on the left is divided by the value or variable on the right and assigns the result to the variable on the left.

     

6. Bitwise AND Assignment Operator (&=)

This operator performs a bitwise AND between the variable on the left and the value on the right and assigns the result to the variable on the left.

   

7. Bitwise OR Assignment Operator (|=)

The bitwise OR assignment operator performs a bitwise OR between the variable on the left and the value or variable on the right and assigns the result to the variable on the left.

8. Bitwise XOR Assignment Operator (^=)

The bitwise XOR assignment operator performs a bitwise XOR between the variable on the left and the value or variable on the right and assigns the result to the variable on the left.

9. Left Shift Assignment Operator (<<=)

The left shift assignment operator shifts the bits of the variable on the left to left by the number of positions specified on the right and assigns the result to the variable on the left.

10. Right Shift Assignment Operator (>>=)

The right shift assignment operator shifts the bits of the variable on the left to the right by a number of positions specified on the right and assigns the result to the variable on the left.

Also, it is important to note that all of the above operators can be overloaded for custom operations with user-defined data types to perform the operations we want.

Please Login to comment...

Similar reads.

  • Geeks Premier League
  • Geeks Premier League 2023
  • Top Android Apps for 2024
  • Top Cell Phone Signal Boosters in 2024
  • Best Travel Apps (Paid & Free) in 2024
  • The Best Smart Home Devices for 2024
  • 15 Most Important Aptitude Topics For Placements [2024]

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

A Way FORWARD for 1/c Mackenzie Bucki: Summer Assignment Series

1/c Bucki

“For this patrol, our mission was to intercept drugs from smuggling vessels in the Caribbean. We left Virginia on May 28th and made four port calls along the way: Key West, Puerto Rico, Columbia, and Cuba,” said Bucki.

Bucki witnessed, first-hand, the training that goes into cutter operations to prep for a mission. She and the crew simulated a “fast cruise” which is a simulated underway day, which allowed the crew to conduct various trainings before the patrol begins. FORWARD also did a “shakedown cruise” where the crew trains in their actual roles while the ship is underway. The shakedown cruise is vital for crewmembers to familiarize themselves with shipboard functions at sea.

“There are many different training scenarios for responding to various casualties aboard. I participated in simulated progressive flooding and crankcase explosion casualty,” said Bucki. “During the shakedown cruise the day was jam-packed with training. We simulated a man overboard, practiced dropping anchor, and ensured that everyone knew their assigned role for getting underway.”

Bucki also became qualified in flight operations tasks, which involve the many aspects that go into a helicopter returning to and taking off from the ship. She learned and demonstrated her skills in hose handling, personal protective equipment (PPE), and basic firefighting. She also familiarized herself with the engineering aspects during this patrol, memorizing many parameters (pressure, temperature, etc.) and functions of engine room and auxiliary systems.

Bucki’s action and adventure packed time on USCGC FORWARD led to the building of Coast Guard bonds with crew members, more confidence in her forthcoming role as ensign and a newfound awareness of her own leadership style.

“I am first generation military, so I am not as familiar with the Coast Guard compared to others. This experience helped me explore some possible career paths and understand the life of a junior officer. I came to realize that there are many factors that influence one’s experience as an ensign. Although location and platform are the main components taken into consideration for billet picks, there are many other things that influence what life will be like on a ship. This includes command climate, status of the ship’s equipment, and collateral duties,” said Bucki.

Bucki would like to receive a Buoy Tender or Fast Response Cutter as her first assignment upon graduation.

  • Academy News
  • CGA In The News
  • Academic News
  • Mission News
  • EAGLE In The News

Sponsor Family Application

Thank you for submitting your application to be part of the Sponsor Family Program. Your application will be processed in the upcoming week. Coast Guard Academy’s policy on background screening now requires all adults (everyone 18 and older living in the home) who volunteer to mentor, teach, coach or sponsor cadets, whether on or off Coast Guard Academy grounds, to be screened every 5 years. They are required to provide personal information (name, birth date and social security number) for the purpose of conducting a criminal background check.

The Security Officer at the Coast Guard Academy, CWO2 Gina Polkowski, is overseeing this process. Her email is:  [email protected].

Sponsor Family designations fall into several different categories. Below are the guidelines to help you determine how best to meet the background screening requirement:

  • If you are Coast Guard active duty you do not need to apply for an additional Background Check. You will be vetted through the Coast Guard system by CWO2 Polkowski.
  • If you are a Civilian working for the Coast Guard you do not need to apply for an additional Background Check. You will be vetted through the Coast Guard system by CWO2 Polkowski.
  • If you are non-Coast Guard Active Duty, you are required to provide proof of your current security clearance or National Agency Check that is to be emailed by your Command Security Officer (CSO)/ Security Office to CWO2 Polkowski at  [email protected].
  • If you are non-Coast Guard civilian who has a current security clearance or National Agency check, you are required to provide proof of your current security clearance or National Agency Check that is to be emailed by your Command Security Officer (CSO)/ Security Office to CWO2 Polkowski at  [email protected].
  • All civilians in the families who are 18 years or older and do not have a security clearance or a National Agency Check are required to be vetted through Mind Your Business, the third party vendor hired by the Coast Guard Academy for the vetting process.

After you complete your application, please e-mail the Sponsor Family Program Coordinator at [email protected] . In your e-mail, you must include the e-mail address and phone number of every adult living in the home. The Sponsor Family Coordinator will then initiate the background check process and you will receive an email with further instructions.

Important things to note:

There is a Sponsor Family Training that is a one-hour training which we ask sponsors to attend once every four years. This training is designed to give you an overview of the program, what is expected of you as a sponsor, and what you can expect from your cadets. This training will also help familiarize you with the cadet regulations onboard CGA. You will be notified via e-mail once the training is scheduled.

The matching process of swabs to families will occur during July and August. Please bear with us and remain flexible through this process. There will be a meet and greet scheduled on Campus, typically in late August. This will give families an opportunity to formally meet their cadet if they have not already done so. Details on this will also be via email.

CGA Badge

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

Collectives™ on Stack Overflow

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

Q&A for work

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

Get early access and see previews of new features.

Assignment by product (multiplication assignment) with increment or decrement in C++? [duplicate]

Why do we get different results for the two follow statements:

the output is 26; whereas the next example returns 30, though they are same?!

  • variable-assignment
  • multiplication

Abdulkarim Kanaan's user avatar

  • 9 Isn't that undefined? (both of them) –  user2345215 Commented Jan 1, 2014 at 22:26
  • 4 Both are undefined behavior. The stored value of a variable shall not be modified more than once between sequence points. –  IInspectable Commented Jan 1, 2014 at 22:27
  • 2 Undefined behaviour means, you are wrong no matter what you expect. Undefined behaviour means, you do not have any justified reason to expect any particular result. –  Oswald Commented Jan 1, 2014 at 22:30
  • 1 @kuroi No, the behavior is genuinely undefined. Implementation-defined is another class, for example, how the NULL macro is defined is implementation-defined. –  IInspectable Commented Jan 1, 2014 at 22:31
  • 1 @llnspectable : you're right. I was too quick to answer this one. My bad. –  kuroi neko Commented Jan 1, 2014 at 22:42

2 Answers 2

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.

In this case, incrementing x (a modification) is unsequenced with the other two value computation of x .

In this case, incrementing x is unsequenced with the value computation of x on the left.

For the meaning of undefined behaviour, see C++11 §1.3.24:

undefined behavior behavior for which this International Standard imposes no requirements

Joseph Mansfield's user avatar

  • 1 "incrementing x is unsequenced" that is, the modification of x is unsequenced to the other two value computations. (It is sequenced after the value computation of the x++ .) –  dyp Commented Jan 1, 2014 at 22:33
  • I'm just wondering, what's the reasoning for undefined and not just unspecified evaluation order? –  user2345215 Commented Jan 1, 2014 at 22:33
  • @user2345215 I'm fairly sure it's to allow the compilers to perform optimizations under the assumption that the programmer doesn't do this. Somebody else might have a better answer though. –  Joseph Mansfield Commented Jan 1, 2014 at 22:38
  • 2 The compiler is supposed to let some operations run simultaneously (on different CPU cores). Hardware might do bizarre things (e.g. generate junk or throw an exception) when 2 cores read and write the same variable simultaneously. Since UB allows doing these things, compiler has much less to worry about when deciding how to do parallelization. –  anatolyg Commented Jan 1, 2014 at 22:56

Assigning a ++'d value to the original value is undefined behavior. So it makes sense that assigning a ++'d then multiplied value is also undefined.

BWG's user avatar

Not the answer you're looking for? Browse other questions tagged c++ operators variable-assignment increment multiplication or ask your own question .

  • The Overflow Blog
  • At scale, anything that could fail definitely will
  • Best practices for cost-efficient Kafka clusters
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Will a Cavalier's mount grow upon maturity if it already grew from the dedication?
  • What's "the archetypal book" called?
  • Can Christian Saudi Nationals Visit Mecca?
  • Is it a date format of YYMMDD, MMDDYY, and/or DDMMYY?
  • Why does this theta function value yield such a good Riemann sum approximation?
  • What should I do if my student has quarrel with my collaborator
  • Invest smaller lump sum vs investing (larger) monthly amount
  • How should I tell my manager that he could delay my retirement with a raise?
  • Testing if a string is a hexadecimal string in LaTeX3: code review, optimization, expandability, and protection
  • Word for when someone tries to make others hate each other
  • Whats the safest way to store a password in database?
  • If a Palestinian converts to Judaism, can they get Israeli citizenship?
  • Convert 8 Bit brainfuck to 1 bit Brainfuck / Boolfuck
  • Is it possible to travel to USA with legal cannabis?
  • Alternative to a single high spec'd diode
  • How do I learn more about rocketry?
  • Light switch that is flush or recessed (next to fridge door)
  • Why doesn’t dust interfere with the adhesion of geckos’ feet?
  • In roulette, is the frequency of getting long sequences of reds lower than that of shorter sequences?
  • What other marketable uses are there for Starship if Mars colonization falls through?
  • quantulum abest, quo minus .
  • Why are poverty definitions not based off a person's access to necessities rather than a fixed number?
  • How to change upward facing track lights 26 feet above living room?
  • Geometry nodes: Curve caps horizontal

c multiplication assignment

IMAGES

  1. C/ multiplication easy practice with 11

    c multiplication assignment

  2. C Program to Generate Multiplication Table

    c multiplication assignment

  3. Program to Generate Multiplication Table in C Language

    c multiplication assignment

  4. Multiplying 3-Digit by 3-Digit Numbers (C)

    c multiplication assignment

  5. Matrix Multiplication

    c multiplication assignment

  6. Multiplication Table in C

    c multiplication assignment

VIDEO

  1. Class X Computer Practical 1 Print welcome in next line Dev C++

  2. C Programming Exercise 1

  3. NPTEL Computer Architecture Week 2 Assignment 2

  4. Fast Math Tricks

  5. Use of Multiplication Assignment in C++

  6. Set C Multiplication Song

COMMENTS

  1. C Multiplication

    The syntax of Multiplication Operator with two operands is. operand1 * operand2. When this operator is given with operands of different numeric datatypes, the lower datatype is promoted to higher datatype. Examples. In the following program, we take two integers in a, b, and find their product using Multiplication Operator. main.c

  2. Assignment operators

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

  3. C Operators

    Multiplication: Multiplies two values: ... Decreases the value of a variable by 1--x: Try it » Assignment Operators. Assignment operators are used to assign values to variables. In the example below, we use the assignment operator (=) to assign the value 10 to a variable called x: Example. int x = 10;

  4. C Operator Precedence

    They are derived from the grammar. In C++, the conditional operator has the same precedence as assignment operators, and prefix ++ and -- and assignment operators don't have the restrictions about their operands. Associativity specification is redundant for unary operators and is only shown for completeness: unary prefix operators always ...

  5. Operators in C

    The operators +, -and * computes addition, subtraction, and multiplication respectively as you might have expected. In normal calculation, 9/4 = 2.25. However, the output is 2 in the ... C Assignment Operators. An assignment operator is used for assigning a value to a variable. The most common assignment operator is = Operator Example Same as ...

  6. Operator Precedence and Associativity in C

    Prerequisite: Operator Overloading The assignment operator,"=", is the operator used for Assignment. It copies the right value into the left value. Assignment Operators are predefined to operate only on built-in Data types. Assignment operator overloading is binary operator overloading.Overloading assignment operator in C++ copies all values of one

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

  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. Operators in C

    5. Assignment Operators in C. Assignment operators are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise ...

  10. Assignment Operators in C

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

  11. Learn C: Operators Cheatsheet

    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: %=

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

  13. c

    1. If your language allows multiplication between a boolean and a number, then yes, that is faster than a conditional. Conditionals require branching, which can invalidate the CPU's pipeline. Also if the branch is big enough, it can even cause a cache miss in the instructions, though that's unlikely in your small example.

  14. C Program to Generate Multiplication Table

    Output. Here, the user input is stored in the int variable n. Then, we use a for loop to print the multiplication table up to 10. printf("%d * %d = %d \n", n, i, n * i); The loop runs from i = 1 to i = 10. In each iteration of the loop, n * i is printed. Here's a little modification of the above program to generate the multiplication table up ...

  15. Arithmetic operators

    Usual arithmetic conversions are performed on both operands. In the remaining description in this section, "operand (s)", lhs and rhs refer to the converted operand (s). 1) The result of built-in multiplication is the product of the operands. Multiplication of a NaN by any number gives NaN.

  16. Arithmetic Operators in C

    These are as follows: 1. Binary Arithmetic Operators in C. The C binary arithmetic operators operate or work on two operands. C provides 5 Binary Arithmetic Operators for performing arithmetic functions which are as follows: Add two operands. Subtract the second operand from the first operand. Multiply two operands.

  17. Assignment operators

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

  18. 6.1

    Chapter introduction. This chapter builds on top of the concepts from lesson 1.9 -- Introduction to literals and operators.A quick review follows: An operation is a mathematical process involving zero or more input values (called operands) that produces a new value (called an output value).The specific operation to be performed is denoted by a construct (typically a symbol or pair of symbols ...

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

  20. A Way FORWARD for 1/c Mackenzie Bucki: Summer Assignment Series

    When it came to her summer assignment, 1/c Mackenzie Bucki got the opposite of what she requested. Instead of a small, patrol boat in the Pacific, she got a 270-foot ship in the Atlantic. The USCGC FORWARD, based in Norfolk, VA, is a medium endurance cutter focusing on migrant and drug interdiction. "For this patrol, […]

  21. operators

    Assignment by product (multiplication assignment) with increment or decrement in C++? [duplicate] Ask Question Asked 10 years, 8 months ago. Modified 10 years, 8 months ago. Viewed 3k times -1 This question ... These both exhibit undefined behaviour in both C++03 and C++11. In C++11 terminology, you can't have two unsequenced modifications of ...