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 - Constants
  • C - Literals
  • C - Escape sequences
  • C - Format Specifiers
  • C - Storage Classes
  • C - 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 - Return Statement
  • C - Recursion
  • C - Scope Rules
  • 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 - Pointer Arithmetics
  • C - Passing Pointers to Functions
  • C - Strings
  • C - Array of Strings
  • C - Structures
  • C - Structures and Functions
  • C - Arrays of Structures
  • C - Pointers to Structures
  • C - Self-Referential Structures
  • C - Nested Structures
  • C - Bit Fields
  • C - Typedef
  • C - Input & Output
  • C - File I/O
  • C - Preprocessors
  • C - Header Files
  • C - Type Casting
  • C - Error Handling
  • C - 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, 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 = 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 −

Simple assignment operator (=)

The = operator is the most frequently used operator in C. As per 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.

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 produces the following result −

C Data Types

C operators.

  • C Input and Output
  • C Control Flow
  • C Functions
  • C Preprocessors

C File Handling

  • C Cheatsheet

C Interview Questions

  • C Programming Language Tutorial
  • C Language Introduction
  • Features of C Programming Language
  • C Programming Language Standard
  • C Hello World Program
  • Compiling a C Program: Behind the Scenes
  • Tokens in C
  • Keywords in C

C Variables and Constants

  • C Variables
  • Constants in C
  • Const Qualifier in C
  • Different ways to declare variable as constant in C
  • Scope rules in C
  • Internal Linkage and External Linkage in C
  • Global Variables in C
  • Data Types in C
  • Literals in C
  • Escape Sequence in C
  • Integer Promotions in C
  • Character Arithmetic in C
  • Type Conversion in C

C Input/Output

  • Basic Input and Output in C
  • Format Specifiers in C
  • printf in C
  • Scansets in C
  • Formatted and Unformatted Input/Output functions in C with Examples

Operators in C

  • Arithmetic Operators in C
  • Unary operators in C
  • Relational Operators in C
  • Bitwise Operators in C
  • C Logical Operators
  • Assignment Operators in C
  • Increment and Decrement Operators in C
  • Conditional or Ternary Operator (?:) in C
  • sizeof operator in C

Operator Precedence and Associativity in C

C control statements decision-making.

  • Decision Making in C (if , if..else, Nested if, if-else-if )
  • C - if Statement
  • C if...else Statement
  • C if else if ladder
  • Switch Statement in C
  • Using Range in switch Case in C
  • while loop in C
  • do...while Loop in C
  • For Versus While
  • Continue Statement in C
  • Break Statement in C
  • goto Statement in C
  • User-Defined Function in C
  • Parameter Passing Techniques in C
  • Function Prototype in C
  • How can I return multiple values from a function?
  • main Function in C
  • Implicit return type int in C
  • Callbacks in C
  • Nested functions in C
  • Variadic functions in C
  • _Noreturn function specifier in C
  • Predefined Identifier __func__ in C
  • C Library math.h Functions

C Arrays & Strings

  • Properties of Array in C
  • Multidimensional Arrays in C
  • Initialization of Multidimensional Array in C
  • Pass Array to Functions in C
  • How to pass a 2D array as a parameter in C?
  • What are the data types for which it is not possible to create an array?
  • How to pass an array by value in C ?
  • Strings in C
  • Array of Strings in C
  • What is the difference between single quoted and double quoted declaration of char array?
  • C String Functions
  • Pointer Arithmetics in C with Examples
  • C - Pointer to Pointer (Double Pointer)
  • Function Pointer in C
  • How to declare a pointer to a function?
  • Pointer to an Array | Array Pointer
  • Difference between constant pointer, pointers to constant, and constant pointers to constants
  • Pointer vs Array in C
  • Dangling, Void , Null and Wild Pointers in C
  • Near, Far and Huge Pointers in C
  • restrict keyword in C

C User-Defined Data Types

  • C Structures
  • dot (.) Operator in C
  • Structure Member Alignment, Padding and Data Packing
  • Flexible Array Members in a structure in C
  • Bit Fields in C
  • Difference Between Structure and Union in C
  • Anonymous Union and Structure in C
  • Enumeration (or enum) in C

C Storage Classes

  • Storage Classes in C
  • extern Keyword in C
  • Static Variables in C
  • Initialization of static variables in C
  • Static functions in C
  • Understanding "volatile" qualifier in C | Set 2 (Examples)
  • Understanding "register" keyword in C

C Memory Management

  • Memory Layout of C Programs
  • Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
  • Difference Between malloc() and calloc() with Examples
  • What is Memory Leak? How can we avoid?
  • Dynamic Array in C
  • How to dynamically allocate a 2D array in C?
  • Dynamically Growing Array in C

C Preprocessor

  • C Preprocessor Directives
  • How a Preprocessor works in C?
  • Header Files in C
  • What’s difference between header files "stdio.h" and "stdlib.h" ?
  • How to write your own header file in C?
  • Macros and its types in C
  • Interesting Facts about Macros and Preprocessors in C
  • # and ## Operators in C
  • How to print a variable name in C?
  • Multiline macros in C
  • Variable length arguments for Macros
  • Branch prediction macros in GCC
  • typedef versus #define in C
  • Difference between #define and const in C?
  • Basics of File Handling in C
  • C fopen() function with Examples
  • EOF, getc() and feof() in C
  • fgets() and gets() in C language
  • fseek() vs rewind() in C
  • What is return type of getchar(), fgetc() and getc() ?
  • Read/Write Structure From/to a File in C
  • C Program to print contents of file
  • C program to delete a file
  • C Program to merge contents of two files into a third file
  • What is the difference between printf, sprintf and fprintf?
  • Difference between getc(), getchar(), getch() and getche()

Miscellaneous

  • time.h header file in C with Examples
  • Input-output system calls in C | Create, Open, Close, Read, Write
  • Signals in C language
  • Program error signals
  • Socket Programming in C
  • _Generics Keyword in C
  • Multithreading in C
  • C Programming Interview Questions (2024)
  • Commonly Asked C Programming Interview Questions | Set 1
  • Commonly Asked C Programming Interview Questions | Set 2
  • Commonly Asked C Programming Interview Questions | Set 3

In C language, operators are symbols that represent operations to be performed on one or more operands. They are the basic components of the C programming. In this article, we will learn about all the built-in operators in C with examples.

What is a C Operator?

An operator in C can be defined as the symbol that helps us to perform some specific mathematical, relational, bitwise, conditional, or logical computations on values and variables. The values and variables used with operators are called operands. So we can say that the operators are the symbols that perform operations on operands.

Operators-in-C

For example,

Here, ‘+’ is the operator known as the addition operator, and ‘a’ and ‘b’ are operands. The addition operator tells the compiler to add both of the operands ‘a’ and ‘b’.

Types of Operators in C

C language provides a wide range of operators that can be classified into 6 types based on their functionality:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Other Operators

1. Arithmetic Operations in C

The arithmetic operators are used to perform arithmetic/mathematical operations on operands. There are 9 arithmetic operators in C language:

Example of C Arithmetic Operators

2. relational operators in c.

The relational operators in C are used for the comparison of the two operands. All these operators are binary operators that return true or false values as the result of comparison.

These are a total of 6 relational operators in C:

Example of C Relational Operators

Here, 0 means false and 1 means true.

3. Logical Operator in C

Logical Operators are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a Boolean value either true or false .

Example of Logical Operators in C

4. bitwise operators in c.

The Bitwise operators are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. Mathematical operations such as addition, subtraction, multiplication, etc. can be performed at the bit level for faster processing.

There are 6 bitwise operators in C:

Example of Bitwise Operators

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

The assignment operators can be combined with some other operators in C to provide multiple operations using single operator. These operators are called compound operators.

In C, there are 11 assignment operators :

Example of C Assignment Operators

6. other operators.

Apart from the above operators, there are some other operators available in C used to perform some specific tasks. Some of them are discussed here: 

sizeof Operator

  • sizeof is much used in the C programming language.
  • It is a compile-time unary operator which can be used to compute the size of its operand.
  • The result of sizeof is of the unsigned integral type which is usually denoted by size_t.
  • Basically, the sizeof the operator is used to compute the size of the variable or datatype.

To know more about the topic refer to this article.

Comma Operator ( , )

  • The comma operator (represented by the token) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type).
  • The comma operator has the lowest precedence of any C operator.
  • Comma acts as both operator and separator. 

Conditional Operator ( ? : )

  • The conditional operator is the only ternary operator in C++.
  • Here, Expression1 is the condition to be evaluated. If the condition(Expression1) is True then we will execute and return the result of Expression2 otherwise if the condition(Expression1) is false then we will execute and return the result of Expression3.
  • We may replace the use of if..else statements with conditional operators.

dot (.) and arrow (->) Operators

  • Member operators are used to reference individual members of classes, structures, and unions.
  • The dot operator is applied to the actual object. 
  • The arrow operator is used with a pointer to an object.

To know more about dot operators refer to this article and to know more about arrow(->) operators refer to this article.

Cast Operator

  • Casting operators convert one data type to another. For example, int(2.2000) would return 2.
  • A cast is a special operator that forces one data type to be converted into another. 
  • The most general cast supported by most of the C compilers is as follows −   [ (type) expression ] .

addressof (&) and Dereference (*) Operators

  • Pointer operator & returns the address of a variable. For example &a; will give the actual address of the variable.
  • The pointer operator * is a pointer to a variable. For example *var; will pointer to a variable var. 

Example of Other C Operators

Unary, binary and ternary operators in c.

Operators can also be classified into three types on the basis of the number of operands they work on:

  • Unary Operators: Operators that work on single operand.
  • Binary Operators: Operators that work on two operands.
  • Ternary Operators: Operators that work on three operands.

In C, it is very common for an expression or statement to have multiple operators and in these expression, there should be a fixed order or priority of operator evaluation to avoid ambiguity.

Operator Precedence and Associativity is the concept that decides which operator will be evaluated first in the case when there are multiple operators present in an expression.

The below table describes the precedence order and associativity of operators in C. The precedence of the operator decreases from top to bottom. 

To know more about operator precedence and associativity, refer to this article – Operator Precedence and Associativity in C

In this article, the points we learned about the operator are as follows:

  • Operators are symbols used for performing some kind of operation in C.
  • There are six types of operators, Arithmetic Operators, Relational Operators, Logical Operators, Bitwise Operators, Assignment Operators, and Miscellaneous Operators.
  • Operators can also be of type unary, binary, and ternary according to the number of operators they are using.
  • Every operator returns a numerical value except logical, relational, and conditional operator which returns a boolean value (true or false).
  • There is a Precedence in the operators means the priority of using one operator is greater than another operator.

FAQs on C Operators

Q1. what are operators in c.

Operators in C are certain symbols in C used for performing certain mathematical, relational, bitwise, conditional, or logical operations for the user.

Q2. What are the 7 types of operators in C?

There are 7 types of operators in C as mentioned below: Unary operator Arithmetic operator Relational operator Logical operator Bitwise operator Assignment operator Conditional operator

Q3. What is the difference between the ‘=’ and ‘==’ operators?

‘=’ is a type of assignment operator that places the value in right to the variable on left, Whereas ‘==’ is a type of relational operator that is used to compare two elements if the elements are equal or not.

Q4. What is the difference between prefix and postfix operators in C?

In prefix operations, the value of a variable is incremented/decremented first and then the new value is used in the operation, whereas, in postfix operations first the value of the variable is used in the operation and then the value is incremented/decremented. Example: b=c=10; a=b++; // a==10 a=++c; // a==11

Q5. What is the Modulo operator?

The Modulo operator(%) is used to find the remainder if one element is divided by another. Example: a % b (a divided by b) 5 % 2 == 1

Please Login to comment...

Similar reads.

  • C-Operators
  • Google Releases ‘Prompting Guide’ With Tips For Gemini In Workspace
  • Google Cloud Next 24 | Gmail Voice Input, Gemini for Google Chat, Meet ‘Translate for me,’ & More
  • 10 Best Viber Alternatives for Better Communication
  • 12 Best Database Management Software in 2024
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

C Functions

C structures, c operators.

Operators are used to perform operations on variables and values.

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

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

C divides the operators into the following groups:

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

Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

Assignment Operators

Assignment operators are used to assign values to variables.

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

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

A list of all assignment operators:

Comparison Operators

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

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

Comparison operators are used to compare two values.

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

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

A list of all comparison operators:

Logical Operators

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

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

C Exercises

Test yourself with exercises.

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

Start the Exercise

Get Certified

COLOR PICKER

colorpicker

Report Error

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

[email protected]

Top Tutorials

Top references, top examples, get certified.

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:

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

PrepBytes Blog

ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING

Sign in to your account

Forgot your password?

Login via OTP

We will send you an one time password on your mobile number

An OTP has been sent to your mobile number please verify it below

Register with PrepBytes

Assignment operator in c.

' src=

Last Updated on June 23, 2023 by Prepbytes

list all the assignment operators in computer programming

This type of operator is employed for transforming and assigning values to variables within an operation. In an assignment operation, the right side represents a value, while the left side corresponds to a variable. It is essential that the value on the right side has the same data type as the variable on the left side. If this requirement is not fulfilled, the compiler will issue an error.

What is Assignment Operator in C language?

In C, the assignment operator serves the purpose of assigning a value to a variable. It is denoted by the equals sign (=) and plays a vital role in storing data within variables for further utilization in code. When using the assignment operator, the value present on the right-hand side is assigned to the variable on the left-hand side. This fundamental operation allows developers to store and manipulate data effectively throughout their programs.

Example of Assignment Operator in C

For example, consider the following line of code:

Types of Assignment Operators in C

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

Simple assignment operator (=): This is the basic assignment operator, which assigns the value on the right-hand side to the variable on the left-hand side.

Addition assignment operator (+=): This operator adds the value on the right-hand side to the variable on the left-hand side and assigns the result back to the variable.

x += 3; // Equivalent to x = x + 3; (adds 3 to the current value of "x" and assigns the result back to "x")

Subtraction assignment operator (-=): This operator subtracts the value on the right-hand side from the variable on the left-hand side and assigns the result back to the variable.

x -= 4; // Equivalent to x = x – 4; (subtracts 4 from the current value of "x" and assigns the result back to "x")

* Multiplication assignment operator ( =):** This operator multiplies the value on the right-hand side with the variable on the left-hand side and assigns the result back to the variable.

x = 2; // Equivalent to x = x 2; (multiplies the current value of "x" by 2 and assigns the result back to "x")

Division assignment operator (/=): This operator divides the variable on the left-hand side by the value on the right-hand side and assigns the result back to the variable.

x /= 2; // Equivalent to x = x / 2; (divides the current value of "x" by 2 and assigns the result back to "x")

Bitwise AND assignment (&=): The bitwise AND assignment operator "&=" performs a bitwise AND operation between the value on the left-hand side and the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x &= 3; // Binary: 0011 // After bitwise AND assignment: x = 1 (Binary: 0001)

Bitwise OR assignment (|=): The bitwise OR assignment operator "|=" performs a bitwise OR operation between the value on the left-hand side and the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x |= 3; // Binary: 0011 // After bitwise OR assignment: x = 7 (Binary: 0111)

Bitwise XOR assignment (^=): The bitwise XOR assignment operator "^=" performs a bitwise XOR operation between the value on the left-hand side and the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x ^= 3; // Binary: 0011 // After bitwise XOR assignment: x = 6 (Binary: 0110)

Left shift assignment (<<=): The left shift assignment operator "<<=" shifts the bits of the value on the left-hand side to the left by the number of positions specified by the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x <<= 2; // Binary: 010100 (Shifted left by 2 positions) // After left shift assignment: x = 20 (Binary: 10100)

Right shift assignment (>>=): The right shift assignment operator ">>=" shifts the bits of the value on the left-hand side to the right by the number of positions specified by the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x >>= 2; // Binary: 101 (Shifted right by 2 positions) // After right shift assignment: x = 5 (Binary: 101)

Conclusion The assignment operator in C, denoted by the equals sign (=), is used to assign a value to a variable. It is a fundamental operation that allows programmers to store data in variables for further use in their code. In addition to the simple assignment operator, C provides compound assignment operators that combine arithmetic or bitwise operations with assignment, allowing for concise and efficient code.

FAQs related to Assignment Operator in C

Q1. Can I assign a value of one data type to a variable of another data type? In most cases, assigning a value of one data type to a variable of another data type will result in a warning or error from the compiler. It is generally recommended to assign values of compatible data types to variables.

Q2. What is the difference between the assignment operator (=) and the comparison operator (==)? The assignment operator (=) is used to assign a value to a variable, while the comparison operator (==) is used to check if two values are equal. It is important not to confuse these two operators.

Q3. Can I use multiple assignment operators in a single statement? No, it is not possible to use multiple assignment operators in a single statement. Each assignment operator should be used separately for assigning values to different variables.

Q4. Are there any limitations on the right-hand side value of the assignment operator? The right-hand side value of the assignment operator should be compatible with the data type of the left-hand side variable. If the data types are not compatible, it may lead to unexpected behavior or compiler errors.

Q5. Can I assign the result of an expression to a variable using the assignment operator? Yes, it is possible to assign the result of an expression to a variable using the assignment operator. For example, x = y + z; assigns the sum of y and z to the variable x.

Q6. What happens if I assign a value to an uninitialized variable? Assigning a value to an uninitialized variable will initialize it with the assigned value. However, it is considered good practice to explicitly initialize variables before using them to avoid potential bugs or unintended behavior.

Leave a Reply Cancel reply

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

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

  • Linked List
  • Segment Tree
  • Backtracking
  • Dynamic Programming
  • Greedy Algorithm
  • Operating System
  • Company Placement
  • Interview Tips
  • General Interview Questions
  • Data Structure
  • Other Topics
  • Computational Geometry
  • Game Theory

Related Post

Null character in c, ackermann function in c, median of two sorted arrays of different size in c, number is palindrome or not in c, implementation of queue using linked list in c, c program to replace a substring in a string.

cppreference.com

Assignment operators.

Assignment operators modify the value of the object.

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

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 must have higher precedence than an assignment expression.
  • ↑ new-value cannot be a comma expression, because its precedence is lower.

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

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

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

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:

[ 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:

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:

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

[ edit ] Example

Possible output:

[ edit ] Defect reports

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

[ edit ] See also

Operator precedence

Operator overloading

  • 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 22:41.
  • This page has been accessed 410,142 times.
  • Privacy policy
  • About cppreference.com
  • Disclaimers

Powered by MediaWiki

Library homepage

  • school Campus Bookshelves
  • menu_book Bookshelves
  • perm_media Learning Objects
  • login Login
  • how_to_reg Request Instructor Account
  • hub Instructor Commons
  • Download Page (PDF)
  • Download Full Book (PDF)
  • Periodic Table
  • Physics Constants
  • Scientific Calculator
  • Reference & Cite
  • Tools expand_more
  • Readability

selected template will load here

This action is not available.

Engineering LibreTexts

4.6: Assignment Operator

  • Last updated
  • Save as PDF
  • Page ID 29038

  • Patrick McClanahan
  • San Joaquin Delta College

Assignment Operator

The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within C++ programming language the symbol used is the equal symbol. But bite your tongue, when you see the = symbol you need to start thinking: assignment. The assignment operator has two operands. The one to the left of the operator is usually an identifier name for a variable. The one to the right of the operator is a value.

The value 21 is moved to the memory location for the variable named: age. Another way to say it: age is assigned the value 21.

The item to the right of the assignment operator is an expression. The expression will be evaluated and the answer is 14. The value 14 would assigned to the variable named: total_cousins.

The expression to the right of the assignment operator contains some identifier names. The program would fetch the values stored in those variables; add them together and get a value of 44; then assign the 44 to the total_students variable.

As we have seen, assignment operators are used to assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of the variable on the left side otherwise the compiler will raise an error. Different types of assignment operators are shown below:

  • “=” : This is the simplest assignment operator, which was discussed above. This operator is used to assign the value on the right to the variable on the left. For example: a = 10; b = 20; ch = 'y';

If initially the value 5 is stored in the variable a,  then:  (a += 6) is equal to 11.  (the same as: a = a + 6)

If initially value 8 is stored in the variable a, then (a -= 6) is equal to  2. (the same as a = a - 6)

If initially value 5 is stored in the variable a,, then (a *= 6) is equal to 30. (the same as a = a * 6)

If initially value 6 is stored in the variable a, then (a /= 2) is equal to 3. (the same as a = a / 2)

Below example illustrates the various Assignment Operators:

Definitions

 Adapted from:  "Assignment Operator"  by  Kenneth Leroy Busbee , (Download for free at http://cnx.org/contents/[email protected] ) is licensed under  CC BY 4.0

MarketSplash

Mastering The Art Of Assignment: Exploring C Assignment Operators

Dive into the world of C Assignment Operators in our extensive guide. Understand the syntax, deep-dive into variables, and explore complex techniques and practical applications.

💡 KEY INSIGHTS

  • Assignment operators in C are not just for basic value assignment; they enable simultaneous arithmetic operations, enhancing code efficiency and readability.
  • The article emphasizes the importance of understanding operator precedence in C, as misinterpretation can lead to unexpected results, especially with compound assignment operators.
  • Common mistakes like confusing assignment with equality ('=' vs '==') are highlighted, offering practical advice for avoiding such pitfalls in C programming.
  • The guide provides real-world analogies for each assignment operator, making complex concepts more relatable and easier to grasp for programmers.
Welcome, bold programmers and coding enthusiasts! Let's set the stage: you're at your desk, fingers hovering over the keyboard, ready to embark on a journey deep into the belly of C programming. You might be wondering, why do I need to know about these 'assignment operators'?

Well, imagine trying to build a house with a toolbox that only has a hammer. You could probably make something that vaguely resembles a house, but without a screwdriver, wrench, or saw, it's going to be a bit...wobbly. This, my friends, is the importance of understanding operators in C. They're like the indispensable tools in your coding toolbox. And today, we're honing in on the assignment operators .

Now, our mission, should we choose to accept it, is to delve into the world of assignment operators in C. Like secret agents discovering the inner workings of a villain's lair, we're going to uncover the secrets that these '=' or '+=' symbols hold.

To all the night owls out there, I see you, and I raise you an operator. Just like how a cup of coffee (or three) helps us conquer that midnight oil, mastering operators in C can transform your coding journey from a groggy stumble to a smooth sprint.

But don't just take my word for it. Let's take a real-world example. Imagine you're coding a video game. You need your character to jump higher each time they collect a power-up. Without assignment operators, you'd be stuck adding numbers line by line. But with the '+=' operator, you can simply write 'jumpHeight += powerUpBoost,' and your code becomes a thing of elegance. It's like going from riding a tricycle to a high-speed motorbike.

In this article, we're going to unpack, examine, and get intimately acquainted with these assignment operators. We'll reveal their secrets, understand their behaviors, and learn how to use them effectively to power our C programming skills to new heights. Let's strap in, buckle up, and get ready for takeoff into the cosmic realms of C assignment operators!

The Basics Of C Operators

Deep dive into assignment operators in c, detailed exploration of each assignment operator, common use cases of assignment operators, common mistakes and how to avoid them, practice exercises, references and further reading.

Alright, get ready to pack your mental suitcase as we prepare to embark on the grand tour of C operators. We'll be stopping by the various categories, getting to know the locals (the operators, that is), and understanding how they contribute to the vibrant community that is a C program.

What Are Operators In C?

Operators in C are like the spicy condiments of coding. Without them, you'd be left with a bland dish—or rather, a simple list of variables. But splash on some operators, and suddenly you've got yourself an extravagant, dynamic, computational feast. In technical terms, operators are special symbols that perform specific operations on one, two, or three operands, and then return a result . They're the magic sauce that allows us to perform calculations, manipulate bits, and compare data.

Categories Of Operators In C

Now, just as you wouldn't use hot sauce on your ice cream (unless that's your thing), different operators serve different purposes. C language has been generous enough to provide us with a variety of operator categories, each with its distinct charm and role.

Let's break it down:

Imagine you're running a pizza shop. The arithmetic operators are like your basic ingredients: cheese, sauce, dough. They form the foundation of your pizza (program). But then you want to offer different pizza sizes. That's where your relational operators come in, comparing the diameter of small, medium, and large pizzas.

You're going well, but then you decide to offer deals. Buy two pizzas, get one free. Enter the logical operators , evaluating whether the conditions for the deal have been met. And finally, you want to spice things up with some exotic ingredients. That's your bitwise operators , working behind the scenes, adding that unique flavor that makes your customers keep coming back.

However, today, we're going to focus on a particular subset of the arithmetic operators: the assignment operators . These are the operators that don't just make the pizza but ensure it reaches the customer's plate (or in this case, the right variable).

Next up: We explore these unsung heroes of the programming world, toasting their accomplishments and discovering their capabilities. So, hold onto your hats and glasses, folks. This here's the wildest ride in the coding wilderness!

Prepare your diving gear and adjust your oxygen masks, friends, as we're about to plunge deep into the ocean of C programming. Hidden in the coral reef of code, you'll find the bright and beautiful creatures known as assignment operators.

What Are Assignment Operators?

In the broad ocean of C operators, the assignment operators are the dolphins - intelligent, adaptable, and extremely useful. On the surface, they may appear simple, but don't be fooled; these creatures are powerful. They have the capability to not only assign values to variables but also perform arithmetic operations concurrently.

The basic assignment operator in C is the '=' symbol. It's like the water of the ocean, essential to life (in the world of C programming). But alongside this staple, we have a whole family of compound assignment operators including '+=', '-=', '*=', '/=', and '%='. These are the playful dolphins leaping out of the water, each adding their unique twist to the task of assignment.

Syntax And Usage Of Assignment Operators

Remember, even dolphins have their ways of communicating, and so do assignment operators. They communicate through their syntax. The syntax for assignment operators in C follows a simple pattern:

In this dance, the operator and the '=' symbol perform a duet, holding onto each other without a space in between. They're the dancing pair that adds life to the party (aka your program).

Let's say you've won the lottery (congratulations, by the way!) and you want to divide your winnings between your three children. You could write out the arithmetic long-hand, or you could use the '/=' operator to streamline your process:

Just like that, your winnings are divided evenly, no calculator required.

List Of Assignment Operators In C

As promised, let's get to know the whole family of assignment operators residing in the C ocean:

Alright, we've taken the plunge and gotten our feet wet (or fins, in the case of our dolphin friends). But the dive is far from over. Next up, we're going to swim alongside each of these assignment operators, exploring their unique behaviors and abilities in the wild, vibrant world of C programming. So, keep your scuba gear on and get ready for more underwater adventure!

Welcome back, dear diver! Now that we've acquainted ourselves with the beautiful pod of dolphins, aka assignment operators, it's time to learn about each dolphin individually. We're about to uncover their quirks, appreciate their styles, and recognize their talents.

The Simple Assignment Operator '='

Let's start with the leader of the pack: the '=' operator. This unassuming symbol is like the diligent mail carrier, ensuring the right packages (values) get to the correct houses (variables).

Take a look at this:

In this code snippet, '=' ensures that the value '5' gets assigned to the variable 'chocolate'. Simple as that. No muss, no fuss, just a straightforward delivery of value.

The Addition Assignment Operator '+='

Next, we have the '+=' operator. This operator is a bit like a friendly baker. He takes what he has, adds more ingredients, and gives you the result - a delicious cake! Or, in this case, a new value.

Consider this:

We started with 12 doughnuts. But oh look, a friend dropped by with 3 more! So we add those to our box, and now we have 15. The '+=' operator made that addition quick and easy.

The Subtraction Assignment Operator '-='

Following the '+=' operator, we have its twin but with a different personality - the '-=' operator. If '+=' is the friendly baker, then '-=' is the weight-conscious friend who always removes extra toppings from their pizza. They take away rather than add.

For instance:

You've consumed 2000 calories today, but then you went for a run and burned 500. The '-=' operator is there to quickly update your calorie count.

The Multiplication Assignment Operator '*='

Say hello to the '*=' operator. This one is like the enthusiastic party planner who multiplies the fun! They take your initial value and multiply it with another, bringing more to the table.

Check this out:

You're at a level 7 excitement about your upcoming birthday, but then you learn that your best friend is flying in to celebrate with you. Your excitement level just doubled, and '*=' is here to make that calculation easy.

The Division Assignment Operator '/='

Here's the '/=' operator, the calm and composed yoga teacher of the group. They're all about division and balance. They take your original value and divide it by another, bringing harmony to your code.

You're pretty anxious about your job interview - let's say a level 10 anxiety. But then you do some deep breathing exercises, which helps you halve your anxiety level. The '/=' operator helps you reflect that change in your code.

The Modulus Assignment Operator '%='

Finally, we meet the quirky '%=' operator, the mystery novelist of the group. They're not about the whole story but the remainder, the leftovers, the little details others might overlook.

Look at this:

You have 10 books to distribute equally among your 3 friends. Everyone gets 3, and you're left with 1 book. The '%=' operator is there to quickly calculate that remainder for you.

That's the end of our detailed exploration. I hope this underwater journey has provided you with a greater appreciation and understanding of these remarkable creatures. Remember, each operator, like a dolphin, has its unique abilities, and knowing how to utilize them effectively can greatly enhance your programming prowess.

Now, let's swerve away from the theoretical and deep-dive into the practical. After all, C assignment operators aren't just sparkling little seashells you collect and admire. They're more like versatile tools in your programming Swiss Army knife. So, let's carve out some real-world use cases for our cherished assignment operators.

Variable Initialization And Value Change

Assignment operators aren't just for show; they've got some moves. Take our plain and humble '='. It's the bread-and-butter operator used in variable initialization and value changes, helping your code be as versatile as a chameleon.

In this scenario, our friend '=' is doing double duty—initializing 'a' with the value 10 and then changing it to 20. Not flashy, but oh-so-vital.

Calculation Updates In Real-Time Applications

Assignment operators are like those awesome, multitasking waitstaff you see in busy restaurants, juggling multiple tables and orders while still managing to serve everyone with a smile. They are brilliant when you want to perform real-time updates to your data.

In this scenario, '+=' and '-=' are the maitre d' of our code-restaurant, updating the user's balance with each buy or sell order.

Running Totals And Averages

Assignment operators are great runners - they don't tire and always keep the tally running.

Here, the '+=' and '-=' operators keep a running tally of points, allowing the system to adjust to the ebbs and flows of the school year like a seasoned marathon runner pacing themselves.

Iterations In Loop Constructs

The '*=' and '/=' operators often lurk within loop constructs, handling iterations with the grace of a prima ballerina. They're the choreographers of your loops, making sure each iteration flows seamlessly into the next.

In this case, '/=' is the elegant dancer gracefully halving 'i' with each twirl across the dance floor (iteration).

Working With Remainders

And let's not forget our mysterious '%=', the detective of the bunch, always searching for the remainder, the evidence left behind.

Here, '%=' is the sleuth, determining whether a number is even or odd by examining the remainder when divided by 2.

So, these are just a few examples of how assignment operators flex their muscles in the real world. They're like superheroes, each with their unique powers, ready to assist you in writing clean, efficient, and understandable code. Use them wisely, and your code will be as smooth as a well-choreographed ballet.

Let's face it, even the best of us trip over our own feet sometimes. And when it comes to assignment operators in C, there are some pitfalls that could make you stumble. But don't worry! We've all been there. Let's shed some light on these common mistakes so we can step over them with the grace of a ballet dancer leaping over a pit of snapping alligators.

Confusing Assignment With Equality

A surprisingly common misstep is confusing the assignment operator '=' with the equality operator '=='. It's like mixing up salt with sugar while baking. Sure, they might look similar, but one will definitely not sweeten your cake.

In this snippet, instead of checking if 'a' equals 10, we've assigned 'a' the value 10. The compiler will happily let this pass and might even give you a standing ovation for your comedy of errors. The correct approach?

Overlooking Operator Precedence

C operators are a bit like the characters in "Game of Thrones." They've got a complex hierarchy and they respect the rule of precedence. Sometimes, this can lead to unexpected results. For instance, check out this bit of misdirection:

Here, '/=' doesn't immediately divide 'a' by 2. It waits for the multiplication to happen (due to operator precedence), and then performs the operation. So it's actually doing a /= (2*5), not (a/=2)*5. It's like arriving late to a party and finding out all the pizza is gone. To ensure you get your slice, use parentheses:

Misusing Modulo With Floats

Ah, the modulo operator, always looking for the remainder. But when you ask it to work with floats, it gets as confused as a penguin in a desert. It simply can't compute.

Modulo and floats go together like oil and water. The solution? Stick to integers when dealing with '%='.

So there you have it. Some common missteps while dancing with assignment operators and the quick moves to avoid them. Just remember, every great coder has tripped before. The key is to keep your chin up, learn from your stumbles, and soon you'll be waltzing with assignment operators like a seasoned pro.

Alright, amigos! It's time to put your newfound knowledge to the test. After all, becoming a master in the art of C assignment operators is not a walk in the park, it's a marathon run on a stony path with occasional dance-offs. So brace yourselves and let's get those brain cells pumping.

Exercise 1: The Shy Variable

Your task here is to write a C program that initializes an integer variable to 10. Then, using only assignment operators, make that variable as shy as a teenager at their first dance. I mean, reduce it to zero without directly assigning it to zero. You might want to remember the '/=' operator here. He's like the high school wallflower who can suddenly breakdance like a champ when the music starts playing.

Exercise 2: Sneaky Increment

The '+=' operator is like the mischievous friend who always pushes you into the spotlight when you least expect it. Create a program that initializes an integer to 0. Then, using a loop and our sneaky '+=' friend, increment that variable until it's equal to 100. Here's the catch: You can't use '+=' with anything greater than 1. It's a slow and steady race to the finish line!

Exercise 3: Modulo Madness

Remember the modulo operator? It's like the friend who always knows how much pizza is left over after a party. Create a program that counts from 1 to 100. But here's the twist: for every number that's divisible by 3, print "Fizz", and for every number divisible by 5, print "Buzz". If a number is divisible by both 3 and 5, print "FizzBuzz". For all other numbers, just print the number. This will help you get better acquainted with our friend '%='.

Exercise 4: Swapping Values

Create a program that swaps the values of two variables without using a third temporary variable. Remember, your only allies here are the assignment operators. This is like trying to switch places on the dance floor without stepping on anyone's toes.

Exercise 5: Converting Fahrenheit To Celsius

Let's play with the ' =' operator. Write a program that converts a temperature in Fahrenheit to Celsius. The formula to convert Fahrenheit to Celsius is (Fahrenheit - 32) * 5 / 9 . As a challenge, try doing the conversion in a single line using the '-=', ' =' and '/=' operators. It's like preparing a complicated dinner recipe using only a few simple steps.

Remember, practice makes perfect, especially when it comes to mastering C assignment operators. Don't be disheartened if you stumble, just dust yourself off and try again. Because as the saying goes, "The master has failed more times than the beginner has even tried". So, good luck, and happy coding!

References and Further Reading

So, you've reached the end of this riveting journey through the meadows of C assignment operators. It's been quite a ride, hasn't it? We've shared laughs, shed tears, and hopefully, we've learned a thing or two. But remember, the end of one journey marks the beginning of another. It's like eating at a buffet – you might be done with the pasta, but there's still the sushi to try! So, here are some materials to sink your teeth into for the next course of your coding feast.

1. The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

This book, also known as 'K&R' after its authors, is the definitive guide to C programming. It's like the "Godfather" of programming books – deep, powerful, and a little intimidating at times. But hey, we all know that the best lessons come from challenging ourselves.

2. Expert C Programming by Peter van der Linden

Consider this book as the "Star Wars" to the "Godfather" of 'K&R'. It has a bit more adventure and a lot of real-world applications to keep you engaged. Not to mention some rather amusing footnotes.

3. C Programming Absolute Beginner's Guide by Greg Perry and Dean Miller

This one's for you if you're still feeling a bit wobbly on your C programming legs. Think of it as a warm hug from a friend who's been there and done that. It's simple, straightforward, and gently walks you through the concepts.

4. The Pragmatic Programmer by Andrew Hunt and David Thomas

Even though it's not about C specifically, this book is a must-read for any serious programmer. It's like a mentor who shares all their best tips and tricks for mastering the craft. It's filled with practical advice and real-life examples to help you on your programming journey.

This is a great online resource for interactive C tutorials. It's like your favorite video game, but it's actually helping you become a better programmer.

6. Cprogramming.com

This website has a vast collection of articles, tutorials, and quizzes on C programming. It's like an all-you-can-eat buffet for your hungry, coding mind.

Remember, every master was once a beginner, and every beginner can become a master. So, keep reading, keep practicing, and keep coding. And most importantly, don't forget to have fun while you're at it. After all, as Douglas Adams said, "I may not have gone where I intended to go, but I think I have ended up where I needed to be." Here's to ending up where you need to be in your coding journey!

As our immersive journey into C Assignment Operators culminates, we've unraveled the nuanced details of these powerful tools. From fundamental syntax to intricate applications, C Assignment Operators have showcased their indispensability in coding. Equipped with this newfound understanding, it's time for you to embark on your coding adventures, mastering the digital realm with the prowess of C Assignment Operators!

Which C assignment operator adds a value to a variable?

Please submit an answer to see if you're correct!

Continue Learning With These C Guides

  • C Syntax Explained: From Variables To Functions
  • C Programming Basics And Its Applications
  • Basic C Programming Examples For Beginners
  • C Data Types And Their Usage
  • C Variables And Their Usage

Subscribe to our newsletter

Subscribe to be notified of new content on marketsplash..

The Simple Assignment Operator

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

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

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

Precedence and Associativity

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

Abbreviated Assignment Operators

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

Auto Increment and Auto Decrement

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

Learn C practically and Get Certified .

Popular Tutorials

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

  • Keywords & Identifier
  • Variables & Constants
  • C Data Types
  • C Input/Output
  • C Operators
  • C Introduction Examples

C Flow Control

  • C if...else
  • C while Loop
  • C break and continue
  • C switch...case
  • C Programming goto
  • Control Flow Examples

C Functions

  • C Programming Functions
  • C User-defined Functions
  • C Function Types
  • C Recursion
  • C Storage Class
  • C Function Examples
  • C Programming Arrays
  • C Multi-dimensional Arrays
  • C Arrays & Function
  • C Programming Pointers
  • C Pointers & Arrays
  • C Pointers And Functions
  • C Memory Allocation
  • Array & Pointer Examples

C Programming Strings

  • C Programming String
  • C String Functions
  • C String Examples

Structure And Union

  • C Structure
  • C Struct & Pointers
  • C Struct & Function
  • C struct Examples

C Programming Files

  • C Files Input/Output
  • C Files Examples

Additional Topics

  • C Enumeration
  • C Preprocessors
  • C Standard Library
  • C Programming Examples

Bitwise Operators in C Programming

C Precedence And Associativity Of Operators

  • Compute Quotient and Remainder
  • Find the Size of int, float, double and char

C if...else Statement

  • Make a Simple Calculator Using switch...case

C Programming Operators

An operator is a symbol that operates on a value or a variable. For example: + is an operator to perform addition.

C has a wide range of operators to perform various operations.

C Arithmetic Operators

An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc on numerical values (constants and variables).

Example 1: Arithmetic Operators

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

It is because both the variables a and b are integers. Hence, the output is also an integer. The compiler neglects the term after the decimal point and shows answer 2 instead of 2.25 .

The modulo operator % computes the remainder. When a=9 is divided by b=4 , the remainder is 1 . The % operator can only be used with integers.

Suppose a = 5.0 , b = 2.0 , c = 5 and d = 2 . Then in C programming,

C Increment and Decrement Operators

C programming has two operators increment ++ and decrement -- to change the value of an operand (constant or variable) by 1.

Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.

Example 2: Increment and Decrement Operators

Here, the operators ++ and -- are used as prefixes. These two operators can also be used as postfixes like a++ and a-- . Visit this page to learn more about how increment and decrement operators work when used as postfix .

C Assignment Operators

An assignment operator is used for assigning a value to a variable. The most common assignment operator is =

Example 3: Assignment Operators

C relational operators.

A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.

Relational operators are used in decision making and loops .

Example 4: Relational Operators

C logical operators.

An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming .

Example 5: Logical Operators

Explanation of logical operator program

  • (a == b) && (c > 5) evaluates to 1 because both operands (a == b) and (c > b) is 1 (true).
  • (a == b) && (c < b) evaluates to 0 because operand (c < b) is 0 (false).
  • (a == b) || (c < b) evaluates to 1 because (a = b) is 1 (true).
  • (a != b) || (c < b) evaluates to 0 because both operand (a != b) and (c < b) are 0 (false).
  • !(a != b) evaluates to 1 because operand (a != b) is 0 (false). Hence, !(a != b) is 1 (true).
  • !(a == b) evaluates to 0 because (a == b) is 1 (true). Hence, !(a == b) is 0 (false).

C Bitwise Operators

During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted to bit-level which makes processing faster and saves power.

Bitwise operators are used in C programming to perform bit-level operations.

Visit bitwise operator in C to learn more.

Other Operators

Comma operator.

Comma operators are used to link related expressions together. For example:

The sizeof operator

The sizeof is a unary operator that returns the size of data (constants, variables, array, structure, etc).

Example 6: sizeof Operator

Other operators such as ternary operator ?: , reference operator & , dereference operator * and member selection operator  ->  will be discussed in later tutorials.

Table of Contents

  • Arithmetic Operators
  • Increment and Decrement Operators
  • Assignment Operators
  • Relational Operators
  • Logical Operators
  • sizeof Operator

Video: Arithmetic Operators in C

Sorry about that.

Related Tutorials

CsTutorialPoint - Computer Science Tutorials For Beginners

Assignment Operators In C [ Full Information With Examples ]

Assignment Operators In C

Assignment Operators In C

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

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

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

x = y = z = 100

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

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

  • Simple assignment operator
  • Compound assignment operators

1. Simple Assignment Operator In C

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

2. Compound Assignment Operators In C

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

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

Look at these two statements:

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

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

Syntax of Compound Assignment Operators

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

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

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

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

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

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

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

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

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

List of Assignment Operators In C

Read More -:

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

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

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

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

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

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

' src=

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

Leave a Reply Cancel reply

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

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

  • Software Engineering
  • Premal Jain Created by
  • 4 (438 ratings)
  • 24 Comments
  • 01/03/2024 Last Updated

1. Introduction

2. History of C Language

3. Features of C Language

4. Use of C Language

5. C Language Download

6. Coding Vs. Programming

7. Structures in C

8. Difference Between Compiler and Interpreter

9. Difference Between Arguments And Parameters

10. C Program to Find ASCII Value of a Character

11. Define And include in C

12. What is Variables in C

13. Boolean in C

14. Conditional Statements in C

15. Constants in C

16. Data Types in C

17. Switch Case in C

18. Data Structures in C

19. C Compiler for Windows

20. C Compiler for Mac

21. Compilation process in C

22. Storage Classes in C

23. Array in C

24. One Dimensional Array in C

25. Two Dimensional Array in C

26. Dynamic Array in C

27. Array of Structure in C

28. Length of an Array in C

29. Array of Pointers in C

30. If Else Statement in C

31. Nested if else statement in C

32. Do While Loop In C

33. Nested Loop in C

34. For Loop in C

35. Difference Between If Else and Switch

36. If Statement in C

37. Operators in C

38. Bitwise Operators in C

39. C Ternary Operator

40. Logical Operators in C

41. Increment and decrement operators in c

42. Conditional operator in the C

43. Relational Operators in C

44. Assignment Operator in C

45. Unary Operator in C

46. Operator Precedence and Associativity in C

47. String Functions in C

48. String Input Output Functions in C

49. Function Pointer in C

50. Functions in C

51. Input and Output Functions in C

52. User Defined Functions in C

53. C Function Call Stack

54. Static function in C

55. Library Function in C

56. Toupper Function in C

57. Ceil Function in C

58. C string declaration

59. String Length in C

60. String Comparison in C

61. Pointers in C

62. Dangling Pointer in C

63. Pointer to Pointer in C

64. Constant Pointer in C

65. String Pointer in C

66. File Handling in C

67. Header Files in C

68. Stack in C

69. Stack Using Linked List in C

70. Linked list in C

71. Implementation of Queue Using Linked List

72. Heap Sort in C Program

73. Tokens in C

74. Enumeration (or enum) in C

75. Format Specifiers in C

76. Strcpy in C

77. Type Casting in C

78. Stdio.h in C

79. Transpose of a Matrix in C

80. Jump Statements in C

81. goto statement in C

82. Double In C

83. Comments in C

84. Types of Error in C

85. strcat() in C

86. Binary to Decimal in C

87. Pre-increment And Post-increment

88. C/C++ Preprocessors

89. How To Install C Language In Mac

90. Evaluation of Arithmetic Expression

91. Random Number Generator in C

92. Random Access Files in C

93. Pattern Programs in C

94. Palindrome Program in C

95. Prime Number Program in C

96. Hello World Program in C

97. Simple interest program in C

98. Anagram Program in C

99. Calculator Program in C

100. C Hello World Program

101. Structure of C Program

102. Program for Linear Search in C

103. C Program for Bubble Sort

104. C Program for Factorial

105. C Program for Prime Numbers

106. Reverse a String in C

107. C Program to Reverse a Number

108. C Program for String Palindrome

109. Debugging C Program

110. How to compile a C program in Linux

111. How to Find a Leap Year Using C Programming

112. Lcm of Two Numbers in C

113. Addition of Two Numbers in C

114. Armstrong Number in C

115. Recursion in C

116. Binary Search in C

117. Matrix multiplication in C

118. Overflow And Underflow in C

119. Dynamic Memory Allocation in C

120. Pseudo-Code In C

121. Fibonacci Series Program in C Using Recursion

122. Macros in C

123. Call by Value and Call by Reference in C

124. Identifiers in C

125. Factorial of A Number in C

126. strlen() in C

127. Convert Decimal to Binary in C

128. Command Line Arguments in C/C++

129. Strcmp in C

130. Square Root in C

Assignment Operator in C

Assignment operators play a vital role in the C programming language, allowing programmers to assign variable values. Understanding assignment operators is crucial for mastering the art of variable manipulation in C. So, let's begin our exploration of assignment operators

This article will explore the world of assignment operators in C, exploring their various types and providing illustrative examples.

What is Assignment Operator in C?

Assignment operators are binary operators in C that enable us to give values or expressions to variables. In C, assignment operators associate from right to left, resulting in the value on the right being assigned to the variable on the left. The variable is always on the left side (LHS), while the value or expression is on the assignment operator's right side (RHS). 

Assignment operators have lower precedence levels compared to other operators in C. You can assign the same value to multiple variables in a single line of code, and the assignment is performed from right to left. The most basic assignment operator symbol is =, which requires two operands.

Let’s check an example of assignment operator in c - 

In an expression like x = 4, the variable x is assigned 4. The variable is on the left side (LHS), and the value or expression is on the assignment operator's right side (RHS). For example:

The assignment operator associates from right to left. For example:

Here, the value 10 is assigned to y first, and then y's value is assigned to x. The simplest explanation of assignment operator associativity can be represented as:

This shows that assignment operators are binary operators, requiring two operands. The LHS operand must be a variable, and the RHS operand can be a constant, variable, or expression.

list all the assignment operators in computer programming

Left Operand = Right Operand

List of All Assignment Operators in C 

In C, we have two types of assignment operators in C: simple assignment operators and compound assignment operators.

Simple Assignment Operator (=):

A simple assignment operator assigns the value on the right-hand side (RHS) to the variable on the left-hand side (LHS)

For example:

The value 5 is assigned to the variable x using the simple assignment operator in the above example.

Compound Assignment Operators (e.g., +=, -=, *=, /=): 

Compound assignment operators combine a binary operator with a simple assignment operator. They perform an operation between the LHS and RHS, and the result is returned to the LHS. 

In the above example, the compound assignment operator += adds 5 to the variable x and returns the result to x.

Compound assignment operators provide a concise way to perform an operation and assign the result in a single statement.

list all the assignment operators in computer programming

Table showcasing list of operators in C

Example Programs

Let’s look at some assignment operators' example - 

Example 1: = Operator

Example 2: += operator, example 3: -= operator, example 4: *= operator, example 5: /= operator, example 6: %= operator, example 7: <<= operator, example 8: >>= operator, example 9: &= operator, example 10: |= operator, example 11: ^= operator, working of assignment operators in c.

Let’s understand the working of Assignment Operators in C with the help of a simple table - 

Assignment operators provide various capabilities, from basic assignments to arithmetic, bitwise, and shift operations. Mastering these operators enables programmers to perform complex calculations and transformations with ease. With their concise syntax and powerful functionality, assignment operators function as a fundamental component of C programming, contributing to code readability and maintainability. The best way to hone proficiency and practical knowledge regarding the same is by upskilling, and what could be better than applying on upGrad for this!

Programming aspirants looking to master skills in software development must consider upGrad’s Executive Post Graduate Program in Software Development - Specialisation in Full Stack Development course offered under the supervision of IIIT-B. This PG program with help learners get an insight into exclusive masterclasses on GenAI, computer science fundamentals, the process of software development, building scalable websites, backend APIs, and much more. Be it a new and seasoned software developer, this program is bound to fuel your flight to success!

1. What is the difference between simple and compound assignment operators in C?

The simple assignment operator (=) assigns the value of the right operand to the left operand. The compound assignment operators (+=, -=, etc.) perform an arithmetic operation and assign the result to the left operand.

2. Can I assign the same value to multiple variables using a single assignment statement?

You can assign the same value to multiple variables using the simple assignment operator in a single line of code, such as "x = y = z = 10;".

3. Are there any precedence rules to consider when using compound assignment operators?

Yes, compound assignment operators have lower precedence than most other operators in C. It's important to use parentheses to clarify the order of operations if necessary, especially when combining compound assignment operators with other arithmetic or bitwise operators.

Leave a Reply

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

Suggested Tutorials

Software Key Tutorial

  • by Mukesh kumar
  • 08 Dec 2023

Python Tutorial

  • 17 Nov 2023

Java Tutorial

  • 26 Sep 2023

Subscribe to our newsletter.

  • Login Forgot Password

list all the assignment operators in computer programming

PW Skills | Blog

Assignment Operators

' src=

Assignment operators play a pivotal role in programming by allowing developers to assign values to variables. These operators are fundamental to most programming languages, including C, C++, Java, etc. In this article, we will explore assignment operators, their types, and how they are used to manipulate data in programs.

Table of Contents

Recommended Course 

  •   Decode DSA with C++
  • Full Stack Data Science Pro Course 
  • Java For Cloud Course 
  • Full Stack Web Development Course
  • Data Analytics Course 

list all the assignment operators in computer programming

An assignment operator consists of two operands: the left-side operand (a variable) and the right-side operand (a value). The operator aims to assign the value on the right side to the variable on the left side. However, there’s a crucial rule: the value’s data type on the right side must match the variable’s data type on the left side. If they don’t match, the compiler will generate an error.

Here is a list of common assignment operators:

  • “=” (Simple Assignment Operator)

The most straightforward assignment operator, “=,” assigns the value on the right to the variable on the left. For instance:

int a = 10;

char ch = ‘y’;

In the first line, the variable a is assigned the value 10, while in the second line, the variable ch is assigned the character ‘y’.

  • “+=” (Addition Assignment Operator)

The “+=” operator combines addition and assignment. It adds the current value of the variable on the left to the value on the right and assigns the result back to the variable on the left. It can be expressed as follows:

a += b; // Equivalent to a = a + b;

Suppose the initial value stored in a is 5. After executing (a += 6), a value becomes 11.

  • “-=” (Subtraction Assignment Operator)

The “-=” operator combines subtraction and assignment. It subtracts the current value of the variable on the left from the value on the right and assigns the result back to the variable on the left. It can be expressed as follows:

a -= b; // Equivalent to a = a – b;

If the initial value stored in a is 8, after executing (a -= 6), a value becomes 2.

  • “*=” (Multiplication Assignment Operator)

The “*=” operator combines multiplication and assignment. It multiplies the current value of the variable on the left by the value on the right and assigns the result back to the variable on the left. It can be expressed as follows:

a *= b; // Equivalent to a = a * b;

If the initial value stored in a is 5, after executing (a *= 6), a value becomes 30.

  • “/=” (Division Assignment Operator)

The “/=” operator combines division and assignment. It divides the current value of the variable on the left by the value on the right and assigns the result back to the variable on the left. It can be expressed as follows:

a /= b; // Equivalent to a = a / b;

If the initial value stored in a is 6, after executing (a /= 2), a value becomes 3.

Putting Assignment Operators to Work

To demonstrate the use of assignment operators, let’s consider a simple C program:

#include <stdio.h>

int main() {

    int a = 10;

    printf(“Value of a is %d\n”, a);

    a += 10;

    a -= 10;

    a *= 10;

    a /= 10;

    return 0;

When executed, this program will output the following:

value of a is 10

value of a is 20

value of a is 100

This output illustrates how assignment operators modify variable A’s value through various arithmetic operations. Assignment operators are fundamental tools in programming, allowing developers to manipulate variables by assigning values based on different operations. Understanding these operators’ behavior is crucial for writing efficient and error-free code. As you continue your programming journey, you’ll encounter these operators frequently and become skilled at using them to build robust and dynamic applications.

Assignment Operators Frequently Asked Questions

Q1.  What’s the operator of an assignment? 

Ans. The assignment operator =Assigns the value of its right-hand operand to a variable, property, or indexer element given by a left-hand operand. The result of an assignment expression is the value assigned to the left-hand operand.

Q2. What are assignment operators in C++?

Ans. The Assignment Operator in C++ is a Binary Operator that uses the symbol “=.” It requires a variable as the left operand and a value to be assigned as the right operand.

Q3. Define add and assignment operators.

Ans. The add and assignment operator adds the value on the right to the left and stores the result on the left. The subtract and assignment operator subtracts the value on the right from the left and stores the result on the left.

  • Basic Java Programs For Beginners

basic java programs for beginners

Basic Java Programs for Beginners are the gateway to a world of possibilities. They in still confidence, unravel the beauty…

  • 35 Basic Java Program Examples with Outputs

basic java program examples

By practicing basic Java program examples, you'll not only enhance your skills but also gain confidence in your abilities. Experimentation…

  • Best Java Course – Best Java Programming Course

best java course

Java developers are always in demand at top tech companies. Earn some necessary certifications to enhance your resume and validate…

right adv

Related Articles

  • Top 10 Best Place To Learn Java In 2024
  • Basic Java Programs For Practice: Java Array Problems
  • Basic Simple Java Programs, Features, Optimization
  • Basics In Javascript: A Comprehensive Guide
  • Basics Of Programming Java, Syntax, Variables And Data Type
  • Architecture Of Spring MVC: Diagram, Examples & Interview Questions
  • Basic Java Program Code: For Beginners, Interview & Examples

bottom banner

Articles Assignment operator

Assignment operator

  • Basic programming

In fact, the assignment operator is the simplest type of computer programming operator. When it comes to variables , it is certainly the first category of operator that you should learn.

Basically, it allows you to modify the values of a variable .

If you still don’t know what a variable in programming is, you should certainly read this article in which we explain in detail about it .

What is the assignment operator?

Represented in most programming languages by the equality symbol = , the assignment operator has the purpose of placing a value inside a variable.

list all the assignment operators in computer programming

David Santiago

Was this article helpful to you, so support us and share it with others who are interested in this subject, other articles.

Algorithm: what is it?

Algorithm: what is it?

Arrays

Recursive Tower of Hanoi (game)

Relational operators

Relational operators

list all the assignment operators in computer programming

Mathematical induction: how do you do it?

Big O notation

Big O notation

Terms of Use

Privacy Policy

list all the assignment operators in computer programming

This website uses cookies to ensure you get the best experience on our website.

Logo for Rebus Press

Want to create or adapt books like this? Learn more about how Pressbooks supports open publishing practices.

Arithmetic Operators

Kenneth Leroy Busbee and Dave Braunschweig

The basic arithmetic operations are addition, subtraction, multiplication, and division. Arithmetic is performed according to an order of operations. [1]

An operator performs an action on one or more operands. The common arithmetic operators are:

These arithmetic operators are binary that is they have two operands. The operands may be either constants or variables.

This expression consists of one operator (addition) which has two operands. The first is represented by a variable named age and the second is a literal constant. If age had a value of 14 then the expression would evaluate (or be equal to) 15.

These operators work as you have learned them throughout your life with the exception of division and modulus. We normally think of division as resulting in an answer that might have a fractional part (a floating-point data type). However, division, when both operands are of the integer data type, may act differently. Please refer to the next section on “Integer Division and Modulus”.

Arithmetic Assignment Operators

Many programming languages support a combination of the assignment ( = ) and arithmetic operators ( + , - , * , / , % ). Various textbooks call them “compound assignment operators” or “combined assignment operators”. Their usage can be explained in terms of the assignment operator and the arithmetic operators. In the table, we will use the variable age and you can assume that it is of integer data type.

  • cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
  • Flowgorithm – Flowchart Programming Language
  • Wikipedia: Arithmetic operators ↵

Programming Fundamentals Copyright © 2018 by Kenneth Leroy Busbee and Dave Braunschweig is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License , except where otherwise noted.

Share This Book

COMMENTS

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

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

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

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

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

  6. Assignment Operator in C

    Here is a list of the assignment operators that you can find in the C language: Simple assignment operator (=): This is the basic assignment operator, which assigns the value on the right-hand side to the variable on the left-hand side. Addition assignment operator (+=): This operator adds the value on the right-hand side to the variable on the ...

  7. Assignment operators

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

  8. 4.5: Assignment Operator

    Discussion. The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within C++ programming language the symbol used is the equal symbol.

  9. 4.6: Assignment Operator

    Assignment Operator. The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within C++ programming language the symbol used is the equal symbol.

  10. Mastering The Art Of Assignment: Exploring C Assignment Operators

    The basic assignment operator in C is the '=' symbol. It's like the water of the ocean, essential to life (in the world of C programming). But alongside this staple, we have a whole family of compound assignment operators including '+=', '-=', '*=', '/=', and '%='. These are the playful dolphins leaping out of the water, each adding their ...

  11. C Programming Course Notes

    Abbreviated Assignment Operators. A very common operation in computer programming is to change a variable in some way and store the new result back into the same variable. E.g. X = X + 7; Because this is so common, there are a number of operators that combine assignment with some other ( binary ) operator.

  12. Operators in C

    C programming has two operators increment ++ and decrement -- to change the value of an operand (constant or variable) by 1. Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.

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

    2. Compound Assignment Operators In C. Compound Assignment Operators use the old value of a variable to calculate its new value and reassign the value obtained from the calculation to the same variable. Examples of compound assignment operators are: (Example: + =, - =, * =, / =,% =, & =, ^ =) Look at these two statements: x = 100; x = x + 5 ...

  14. Discovering C Operators: An Overview with Types and Examples!

    The most basic assignment operator symbol is =, which requires two operands. Let's check an example of assignment operator in c -. In an expression like x = 4, the variable x is assigned 4. The variable is on the left side (LHS), and the value or expression is on the assignment operator's right side (RHS). For example: x = 4; // Assigns the ...

  15. What Are Assignment Operators

    Learning about assignment operators is foundational to programming. They allow us to: - Initiate and change variable values. - Create interactive and responsive programs. - Write more concise and readable code. They are not just symbols on the screen; they pave the way toward mastering programming logic and efficiency.

  16. Assignment Operators

    The Assignment Operator in C++ is a Binary Operator that uses the symbol "=." It requires a variable as the left operand and a value to be assigned as the right operand. Q3. Define add and assignment operators. Ans. The add and assignment operator adds the value on the right to the left and stores the result on the left.

  17. Assignment operator

    In fact, the assignment operator is the simplest type of computer programming operator. When it comes to variables, it is certainly the first category of operator that you should learn. Basically, it allows you to modify the values of a variable. If you still don't know what a variable in programming is, you should certainly read this article ...

  18. Operators: What Role Do They Play in Programming?

    Operators are symbols with defined functions. Programmers use these symbols to tell the interpreter or compiler in high-level computer languages, such as C++, Java, and Python, to perform a particular action. These symbols form the program's foundation, allowing you to perform various actions ranging from simple maths to complex encryption.

  19. Arithmetic Operators

    An operator performs an action on one or more operands. The common arithmetic operators are: These arithmetic operators are binary that is they have two operands. The operands may be either constants or variables. This expression consists of one operator (addition) which has two operands. The first is represented by a variable named age and the ...