CProgramming Tutorial

  • C Programming Tutorial
  • C - Overview
  • C - Features
  • C - History
  • C - Environment Setup
  • C - Program Structure
  • C - Hello World
  • C - Compilation Process
  • C - Comments
  • C - Keywords
  • C - Identifiers
  • C - User Input
  • C - Basic Syntax
  • C - Data Types
  • C - Variables
  • C - Integer Promotions
  • C - Type Conversion
  • C - Booleans
  • C - Constants
  • C - Literals
  • C - Escape sequences
  • C - Format Specifiers
  • C - Storage Classes
  • C - Operators
  • C - Arithmetic Operators
  • C - Relational Operators
  • C - Logical Operators
  • C - Bitwise Operators
  • C - Assignment Operators
  • C - Unary Operators
  • C - Increment and Decrement Operators
  • C - Ternary Operator
  • C - sizeof Operator
  • C - Operator Precedence
  • C - Misc Operators
  • C - Decision Making
  • C - if statement
  • C - if...else statement
  • C - nested if statements
  • C - switch statement
  • C - nested switch statements
  • C - While loop
  • C - For loop
  • C - Do...while loop
  • C - Nested loop
  • C - Infinite loop
  • C - Break Statement
  • C - Continue Statement
  • C - goto Statement
  • C - Functions
  • C - Main Functions
  • C - Function call by Value
  • C - Function call by reference
  • C - Nested Functions
  • C - Variadic Functions
  • C - User-Defined Functions
  • C - Callback Function
  • C - Return Statement
  • C - Recursion
  • C - Scope Rules
  • C - Static Variables
  • C - Global Variables
  • C - Properties of Array
  • C - Multi-Dimensional Arrays
  • C - Passing Arrays to Function
  • C - Return Array from Function
  • C - Variable Length Arrays
  • C - Pointers
  • C - Pointers and Arrays
  • C - Applications of Pointers
  • C - Pointer Arithmetics
  • C - Array of Pointers
  • C - 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 language, the assignment operator stores a certain value in an already declared variable. A variable in C can be assigned the value in the form of a literal, another variable, or an expression.

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

In addition, C has several augmented assignment operators.

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

Simple Assignment Operator (=)

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

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

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

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

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

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

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

Augmented Assignment Operators

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

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

Run the code and check its output −

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

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

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

To Continue Learning Please Login

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

\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

\( \newcommand{\Span}{\mathrm{span}}\)

\( \newcommand{\id}{\mathrm{id}}\)

\( \newcommand{\kernel}{\mathrm{null}\,}\)

\( \newcommand{\range}{\mathrm{range}\,}\)

\( \newcommand{\RealPart}{\mathrm{Re}}\)

\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

\( \newcommand{\Argument}{\mathrm{Arg}}\)

\( \newcommand{\norm}[1]{\| #1 \|}\)

\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

\( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vectorC}[1]{\textbf{#1}} \)

\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

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

Home » Learn C Programming from Scratch » C Assignment Operators

C Assignment Operators

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

Introduction to the C assignment operators

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

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

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

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

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

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

The expression:

is equivalent to the following expression:

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

  • A simple assignment operator assigns the value of the left operand to the right operand.
  • A compound assignment operator performs the operation specified by the additional operator and then assigns the result to the left operand.

Assignment Operators in C

C++ Course: Learn the Essentials

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

Types of Assignment Operators in C

LHS and RHS Operands

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

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

Working of Assignment Operators in C

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

Example for Assignment Operators in C

Basic assignment ( = ) :

Subtraction assignment ( -= ) :

Addition assignment ( += ) :

Division assignment ( /= ) :

Multiplication assignment ( *= ) :

Modulo assignment ( %= ) :

Bitwise XOR assignment ( ^= ) :

Bitwise OR assignment ( |= ) :

Bitwise AND assignment ( &= ) :

Bitwise right shift assignment ( >>= ) :

Bitwise left shift assignment ( <<= ) :

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

Practice Problems on Assignment Operators in C

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

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

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

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

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

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

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

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

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

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

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

c assignment operator with different types

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.

c assignment operator with different types

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

c assignment operator with different types

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

c assignment operator with different types

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.

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

Contact Sales

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

Report Error

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

Top Tutorials

Top references, top examples, get certified.

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

This browser is no longer supported.

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

Assignment operators

  • 8 contributors

expression assignment-operator expression

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

Assignment operators store a value in the object specified by the left operand. There are two kinds of assignment operations:

simple assignment , in which the value of the second operand is stored in the object specified by the first operand.

compound assignment , in which an arithmetic, shift, or bitwise operation is performed before storing the result.

All assignment operators in the following table except the = operator are compound assignment operators.

Assignment operators table

Operator keywords.

Three of the compound assignment operators have keyword equivalents. They are:

C++ specifies these operator keywords as alternative spellings for the compound assignment operators. In C, the alternative spellings are provided as macros in the <iso646.h> header. In C++, the alternative spellings are keywords; use of <iso646.h> or the C++ equivalent <ciso646> is deprecated. In Microsoft C++, the /permissive- or /Za compiler option is required to enable the alternative spelling.

Simple assignment

The simple assignment operator ( = ) causes the value of the second operand to be stored in the object specified by the first operand. If both objects are of arithmetic types, the right operand is converted to the type of the left, before storing the value.

Objects of const and volatile types can be assigned to l-values of types that are only volatile , or that aren't const or volatile .

Assignment to objects of class type ( struct , union , and class types) is performed by a function named operator= . The default behavior of this operator function is to perform a member-wise copy assignment of the object's non-static data members and direct base classes; however, this behavior can be modified using overloaded operators. For more information, see Operator overloading . Class types can also have copy assignment and move assignment operators. For more information, see Copy constructors and copy assignment operators and Move constructors and move assignment operators .

An object of any unambiguously derived class from a given base class can be assigned to an object of the base class. The reverse isn't true because there's an implicit conversion from derived class to base class, but not from base class to derived class. For example:

Assignments to reference types behave as if the assignment were being made to the object to which the reference points.

For class-type objects, assignment is different from initialization. To illustrate how different assignment and initialization can be, consider the code

The preceding code shows an initializer; it calls the constructor for UserType2 that takes an argument of type UserType1 . Given the code

the assignment statement

can have one of the following effects:

Call the function operator= for UserType2 , provided operator= is provided with a UserType1 argument.

Call the explicit conversion function UserType1::operator UserType2 , if such a function exists.

Call a constructor UserType2::UserType2 , provided such a constructor exists, that takes a UserType1 argument and copies the result.

Compound assignment

The compound assignment operators are shown in the Assignment operators table . These operators have the form e1 op = e2 , where e1 is a non- const modifiable l-value and e2 is:

an arithmetic type

a pointer, if op is + or -

a type for which there exists a matching operator *op*= overload for the type of e1

The built-in e1 op = e2 form behaves as e1 = e1 op e2 , but e1 is evaluated only once.

Compound assignment to an enumerated type generates an error message. If the left operand is of a pointer type, the right operand must be of a pointer type, or it must be a constant expression that evaluates to 0. When the left operand is of an integral type, the right operand must not be of a pointer type.

Result of built-in assignment operators

The built-in assignment operators return the value of the object specified by the left operand after the assignment (and the arithmetic/logical operation in the case of compound assignment operators). The resultant type is the type of the left operand. The result of an assignment expression is always an l-value. These operators have right-to-left associativity. The left operand must be a modifiable l-value.

In ANSI C, the result of an assignment expression isn't an l-value. That means the legal C++ expression (a += b) += c isn't allowed in C.

Expressions with binary operators C++ built-in operators, precedence, and associativity C assignment operators

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

Learn C++ practically and Get Certified .

Popular Tutorials

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

  • Getting Started With C++
  • Your First C++ Program
  • C++ Comments

C++ Fundamentals

  • C++ Keywords and Identifiers
  • C++ Variables, Literals and Constants
  • C++ Data Types
  • C++ Type Modifiers
  • C++ Constants
  • C++ Basic Input/Output
  • C++ Operators

Flow Control

C++ Relational and Logical Operators

  • C++ if, if...else and Nested if...else
  • C++ for Loop
  • C++ while and do...while Loop
  • C++ break Statement
  • C++ continue Statement
  • C++ goto Statement
  • C++ switch..case Statement

C++ Ternary Operator

  • C++ Functions
  • C++ Programming Default Arguments
  • C++ Function Overloading
  • C++ Inline Functions
  • C++ Recursion

Arrays and Strings

  • C++ Array to Function
  • C++ Multidimensional Arrays
  • C++ String Class

Pointers and References

  • C++ Pointers
  • C++ Pointers and Arrays
  • C++ References: Using Pointers
  • C++ Call by Reference: Using pointers
  • C++ Memory Management: new and delete

Structures and Enumerations

  • C++ Structures
  • C++ Structure and Function
  • C++ Pointers to Structure
  • C++ Enumeration

Object Oriented Programming

  • C++ Classes and Objects
  • C++ Constructors
  • C++ Constructor Overloading
  • C++ Destructors
  • C++ Access Modifiers
  • C++ Encapsulation
  • C++ friend Function and friend Classes

Inheritance & Polymorphism

  • C++ Inheritance
  • C++ Public, Protected and Private Inheritance
  • C++ Multiple, Multilevel and Hierarchical Inheritance
  • C++ Function Overriding
  • C++ Virtual Functions
  • C++ Abstract Class and Pure Virtual Function

STL - Vector, Queue & Stack

  • C++ Standard Template Library
  • C++ STL Containers
  • C++ std::array
  • C++ Vectors
  • C++ Forward List
  • C++ Priority Queue

STL - Map & Set

  • C++ Multimap
  • C++ Multiset
  • C++ Unordered Map
  • C++ Unordered Set
  • C++ Unordered Multiset
  • C++ Unordered Multimap

STL - Iterators & Algorithms

  • C++ Iterators
  • C++ Algorithm
  • C++ Functor

Additional Topics

  • C++ Exceptions Handling
  • C++ File Handling
  • C++ Ranged for Loop
  • C++ Nested Loop
  • C++ Function Template
  • C++ Class Templates
  • C++ Type Conversion
  • C++ Type Conversion Operators
  • C++ Operator Overloading

Advanced Topics

  • C++ Namespaces
  • C++ Preprocessors and Macros
  • C++ Storage Class

C++ Bitwise Operators

  • C++ Buffers
  • C++ istream
  • C++ ostream

C++ Tutorials

C++ Operator Precedence and Associativity

  • Subtract Complex Number Using Operator Overloading
  • Increment ++ and Decrement -- Operator Overloading in C++ Programming

Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while - is an operator used for subtraction.

Operators in C++ can be classified into 6 types:

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

1. C++ Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations on variables and data. For example,

Here, the + operator is used to add two variables a and b . Similarly there are various other arithmetic operators in C++.

Example 1: Arithmetic Operators

Here, the operators + , - and * compute addition, subtraction, and multiplication respectively as we might have expected.

/ Division Operator

Note the operation (a / b) in our program. The / operator is the division operator.

As we can see from the above example, if an integer is divided by another integer, we will get the quotient. However, if either divisor or dividend is a floating-point number, we will get the result in decimals.

% Modulo Operator

The modulo operator % computes the remainder. When a = 9 is divided by b = 4 , the remainder is 1 .

Note: The % operator can only be used with integers.

  • Increment and Decrement Operators

C++ also provides increment and decrement operators: ++ and -- respectively.

  • ++ increases the value of the operand by 1
  • -- decreases it by 1

For example,

Here, the code ++num; increases the value of num by 1 .

Example 2: Increment and Decrement Operators

In the above program, we have used the ++ and -- operators as prefixes (++a and --b) . However, we can also use these operators as postfix (a++ and b--) .

To learn more, visit increment and decrement operators .

2. C++ Assignment Operators

In C++, assignment operators are used to assign values to variables. For example,

Here, we have assigned a value of 5 to the variable a .

Example 3: Assignment Operators

3. c++ relational operators.

A relational operator is used to check the relationship between two operands. For example,

Here, > is a relational operator. It checks if a is greater than b or not.

If the relation is true , it returns 1 whereas if the relation is false , it returns 0 .

Example 4: Relational Operators

Note : Relational operators are used in decision-making and loops.

4. C++ Logical Operators

Logical operators are used to check whether an expression is true or false . If the expression is true , it returns 1 whereas if the expression is false , it returns 0 .

In C++, logical operators are commonly used in decision making. To further understand the logical operators, let's see the following examples,

Example 5: Logical Operators

Explanation of logical operator program

  • (3 != 5) && (3 < 5) evaluates to 1 because both operands (3 != 5) and (3 < 5) are 1 (true).
  • (3 == 5) && (3 < 5) evaluates to 0 because the operand (3 == 5) is 0 (false).
  • (3 == 5) && (3 > 5) evaluates to 0 because both operands (3 == 5) and (3 > 5) are 0 (false).
  • (3 != 5) || (3 < 5) evaluates to 1 because both operands (3 != 5) and (3 < 5) are 1 (true).
  • (3 != 5) || (3 > 5) evaluates to 1 because the operand (3 != 5) is 1 (true).
  • (3 == 5) || (3 > 5) evaluates to 0 because both operands (3 == 5) and (3 > 5) are 0 (false).
  • !(5 == 2) evaluates to 1 because the operand (5 == 2) is 0 (false).
  • !(5 == 5) evaluates to 0 because the operand (5 == 5) is 1 (true).

5. C++ Bitwise Operators

In C++, bitwise operators are used to perform operations on individual bits. They can only be used alongside char and int data types.

To learn more, visit C++ bitwise operators .

6. Other C++ Operators

Here's a list of some other common operators available in C++. We will learn about them in later tutorials.

  • C++ Operators Precedence and Associativity

Table of Contents

Sorry about that.

Related Tutorials

C++ Tutorial

  • Trending Now
  • Foundational Courses
  • Data Science
  • Practice Problem
  • Machine Learning
  • System Design
  • DevOps Tutorial
  • Learn Programming For Free
  • What is Programming? A Handbook for Beginners
  • How to Learn Programming?

Basic Components of Programming

  • Data Types in Programming
  • Variables in Programming
  • Types of Operators in Programming
  • Conditional Statements in Programming | Definition, Types, Best Practices
  • If-Then-___ Trio in Programming
  • Loops in Programming
  • Functions in Programming
  • Error Handling in Programming

Getting Started with Coding

  • What is a Code in Programming?
  • What Is Coding and What Is It Used For?
  • how to learn how to code
  • Most Famous Online IDE for Programming
  • Getting Started with Number Programs in Programming
  • Getting Started with Words and Sentences Programs in Programming
  • Getting Started with Printing Patterns in Programming
  • Getting Started with Geometry Problems in Programming
  • Getting Started with Date and Time Problems in Programming
  • Getting Started with Menu Driven Programs in Programming

Learn How to Code Popular Character Encoding Systems in Programming

  • What is ASCII - A Complete Guide to Generating ASCII Code
  • Morse Code Tutorial
  • Program for Morse Code Translator (Conversion of Morse Code to English Text)

Types of operators in programming are symbols or keywords that represent computations or actions performed on operands. Operands can be variables , constants , or values , and the combination of operators and operands form expressions. Operators play a crucial role in performing various tasks, such as arithmetic calculations, logical comparisons, bitwise operations, etc.

types-of-operators-in-programming

Table of Content

  • Arithmetic Operators in Programming
  • Comparison Operators in Programming
  • Logical Operators in Programming
  • Assignment Operators in Programming
  • Increment and Decrement Operators in Programming
  • Bitwise Operators in Programming

Types of Operators in Programming:

Here are some common types of operators:

  • Addition ( + )
  • Subtraction ( - )
  • Multiplication ( * )
  • Division ( / )
  • Modulus ( % )
  • Basic Assignment ( = )
  • Add and Assign ( += )
  • Subtract and Assign ( -= )
  • Multiply and Assign ( *= )
  • Divide and Assign ( /= )
  • Modulus and Assign ( %= )
  • Increment ( ++ )
  • Decrement ( -- )
  • Unary Plus ( + )
  • Unary Minus ( - )
  • Logical NOT ( ! )
  • Equal to ( == )
  • Not Equal to ( != )
  • Less Than ( < )
  • Greater Than ( > )
  • Less Than or Equal To ( <= )
  • Greater Than or Equal To ( >= )
  • Logical AND ( && )
  • Logical OR ( || )
  • Bitwise AND ( & )
  • Bitwise OR ( | )
  • Bitwise XOR ( ^ )
  • Bitwise NOT ( ~ )
  • Left Shift ( << )
  • Right Shift ( >> )
  • Ternary Operator ( ?: )

These operators provide the building blocks for creating complex expressions and performing diverse operations in programming languages. Understanding their usage is crucial for writing efficient and expressive code.

Arithmetic Operators in Programming:

Arithmetic operators in programming are fundamental components of programming languages, enabling the manipulation of numeric values for various computational tasks. Here’s an elaboration on the key arithmetic operators:

These operators are foundational for mathematical calculations, financial computations, and various algorithmic implementations. They are commonly used in everyday programming scenarios, providing the tools necessary for handling numerical data and solving mathematical problems within a program. Understanding how to use arithmetic operators is essential for performing precise and efficient calculations in programming.

Comparison Operators in Programming:

Comparison operators in programming are used to compare two values or expressions and return a Boolean result indicating the relationship between them. These operators play a crucial role in decision-making and conditional statements. Here are the common comparison operators:

These operators are extensively used in conditional statements, loops, and decision-making constructs to control the flow of a program based on the relationship between variables or values. Understanding comparison operators is crucial for creating logical and effective algorithms in programming.

Logical Operators in Programming:

Logical operators in programming are used to perform logical operations on Boolean values . These operators are crucial for combining or manipulating conditions and controlling the flow of a program based on logical expressions. Here are the common logical operators:

These logical operators are frequently used in conditional statements (if, else if, else), loops, and decision-making constructs to create complex conditions based on multiple Boolean expressions. Understanding how to use logical operators is essential for designing effective and readable control flow in programming.

Assignment Operators in Programming:

Assignment operators in programming are used to assign values to variables. They are essential for storing and updating data within a program. Here are common assignment operators:

Assignment operators are fundamental for updating variable values, especially in loops and mathematical computations, contributing to the dynamic nature of programming. Understanding how to use assignment operators is essential for effective variable manipulation in a program.

Increment and Decrement Operators in Programming:

Increment and decrement operators in programming are used to increase or decrease the value of a variable by 1, respectively. They are shorthand notations for common operations and are particularly useful in loops. Here are the two types:

These operators are frequently employed in loops, especially for iterating through arrays or performing repetitive tasks. Their concise syntax enhances code readability and expressiveness.

Bitwise Operators in Programming:

Bitwise operators in programming perform operations at the bit level , manipulating individual bits of binary representations of numbers. These operators are often used in low-level programming, such as embedded systems and device drivers. Here are the common bitwise operators:

Bitwise operators are useful in scenarios where direct manipulation of binary representations or specific bit patterns is required, such as optimizing certain algorithms or working with hardware interfaces. Understanding bitwise operations is essential for low-level programming tasks.

In conclusion, operators in programming are essential for tasks like math, comparison, and logical decision-making. They handle basic operations, value comparison, and variable manipulation. Understanding these is crucial for efficient coding in different languages.

Please Login to comment...

Similar reads.

  • Programming

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

IMAGES

  1. Operators In C Logicmojo

    c assignment operator with different types

  2. Assignment Operators in C

    c assignment operator with different types

  3. C Operators

    c assignment operator with different types

  4. Operators In C Language With Types

    c assignment operator with different types

  5. Assignment Operators in C

    c assignment operator with different types

  6. Operators in C

    c assignment operator with different types

VIDEO

  1. Assignment Operator in C Programming

  2. Augmented assignment operators in C

  3. Assignment Operator in C Programming

  4. NPTEL Problem Solving through Programming in C ASSIGNMENT 6 ANSWERS 2024

  5. #7 Operators and its Types in C Language (Part 1) with Notes

  6. Operators in C language

COMMENTS

  1. does assignment operator work with different types of objects?

    2. This isn't an answer, but one should be aware that the typical idiom for the assignment operator is to have it return a reference to the object type (rather than void) and to return (*this) at the end. This way, you can chain the assignent, as in a = b = c: A& operator=(const A& other) {. // manage any deep copy issues here. return *this; }

  2. Assignment Operators in C

    Different types of assignment operators are shown below: 1. "=": This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example: a = 10; b = 20; ch = 'y'; 2. "+=": This operator is combination of '+' and '=' operators. This operator first adds the current ...

  3. c++

    MyObject a; MyObject b; b = a; // calls assignment operator b.operator=(a); Note you can't overload operators in C and Java probably does it differently. Edit: Other things you may want to know as Griwes pointed out is that the compiler will generate an implicit assignment operator for your user defined object if you don't specify one.

  4. Assignment operators

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

  5. Assignment Operators in C

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

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

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

  8. C Assignment Operators

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

  9. Operators in C

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

  10. Assignment Operators in C with Examples

    Assignment operators are used to assign value to a variable. The left side of an assignment operator is a variable and on the right side, there is a value, variable, or an expression. It computes the outcome of the right side and assign the output to the variable present on the left side. C supports following Assignment operators: 1.

  11. Assignment Operators in C

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

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

  13. Operators in C

    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.

  14. Assignment Operators in Programming

    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 the variable on the left side. Types of Assignment Operators: Simple ...

  15. Assignment Operator in C

    Example of Assignment Operator in C. For example, consider the following line of code: int a = 10 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 ...

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

  17. What alternatives are there for C/C++ assignment operator (=) and

    That said, to mean assignment, the =, :=, <-and ← operators are common across many languages descending from C, Pascal and BASIC. Vale uses a set keyword to mean reassignment. In languages where the concept of "(re)assignment" does not exist, like most Functional and Logical ones, it is not uncommon to see = be used both for bindings and as ...

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

  19. Assignment operators

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

  20. C++ Operators

    C++ Operators. Operators are symbols that perform operations on variables and values. For example, + is an operator used for addition, while - is an operator used for subtraction. Operators in C++ can be classified into 6 types: Arithmetic Operators. Assignment Operators.

  21. C++ Assignment Operator Overloading

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

  22. c++

    The commented assignment operator overloading is my attempt to do what I want, I thought it might provide a better description than the one above the snippet. ... That is, use T2 in the parameter type, not in the return type! I would rather use different letter for template parameter: template <class U> Number<T>& operator=( const Number<U ...

  23. Types of Operators in Programming

    Types of operators in programming are symbols or keywords that represent computations or actions performed on operands. Operands can be variables, constants, or values, and the combination of operators and operands form expressions.Operators play a crucial role in performing various tasks, such as arithmetic calculations, logical comparisons, bitwise operations, etc.