- C Data Types
- C Operators
- C Input and Output
- C Control Flow
- C Functions
- C Preprocessors
- C File Handling
- C Cheatsheet
- C Interview Questions
Assignment Operators in C
Assignment operators are used for 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:
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:
2. “+=” : This operator is combination of ‘+’ and ‘=’ operators. This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example:
If initially value stored in a is 5. Then (a += 6) = 11.
3. “-=” This operator is combination of ‘-‘ and ‘=’ operators. This operator first subtracts the value on the right from the current value of the variable on left and then assigns the result to the variable on the left. Example:
If initially value stored in a is 8. Then (a -= 6) = 2.
4. “*=” This operator is combination of ‘*’ and ‘=’ operators. This operator first multiplies the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example:
If initially value stored in a is 5. Then (a *= 6) = 30.
5. “/=” This operator is combination of ‘/’ and ‘=’ operators. This operator first divides the current value of the variable on left by the value on the right and then assigns the result to the variable on the left. Example:
If initially value stored in a is 6. Then (a /= 2) = 3.
Below example illustrates the various Assignment Operators:
Similar Reads
- C-Operators
- cpp-operator
Please Login to comment...
Improve your coding skills with practice.
What kind of Experience do you want to share?
- Tech Partner
- Enterprise Software Development Article Challenge
- Learn Delphi
- DelphiFeeds
- Delphi 25th Anniversary
What Is A Copy Assignment Operator In Modern C++?
Hello everyone, today we have 5 more C++ posts about Copy Assignment Operators . All of the C++ examples in these posts can be used with C++ Builder or the C++ Builder 11 CE Community Edition. They can also be used with Dev-C++ , BCC C++ Compilers , and some other compilers such as the GCC compiler. If you just starting out on your C++ journey and want to jump to a modern IDE and C++ compiler , there is a free version of C++ Builder, C++ Builder 11 CE Community Edition released in April 2023. If you are a start-up developer, student, hobbyist, or just interested in learning to code then the C++ Builder Community Edition may well be just the thing for you.
Table of Contents
Where can I learn Modern C++ with a free C++ compiler?
If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great examples on the LearnCPlusPlus.org website and they’re all completely free . Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org , we have new articles with very simple examples that can be used with:
- The free version of C++ Builder 11 CE Community Edition
- or a professional C++ Builder
- or free BCC32C C++ Compiler and BCC32X C++ Compiler
- or the free Dev-C++
Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE .
What is new in C++ Builder CE?
C++ Builder 11 CE which is the free Edition of C++ Builder has been recently released . Embarcadero has made available a Community Edition license for the most recent 11.3 release of Delphi and C++Builder . This is a free edition of either Delphi or C++Builder for students, hobbyists, and startups (as the license is revenue-limited).
How to use a copy assignment operator in modern C++ with C++ Builder CE?
Object-Oriented Programming (OOP) is a method of mapping real-world objects and data to computer functions and data structures. Classes and Objects are part of object-oriented methods and typically provide features such as properties and methods. One of the features of an OOP Editor is a copy assignment operator that is used with “operator=” to create a new object from an existing one. The Copy Assignment Operator in a class is a non-template non-static member function that is declared with the “ operator= “. This operator allows you to copy objects of classes, structs and unions. When you create a class or a type that is copy assignable (that you can copy with the = operator symbol), it must have a public copy assignment operator. In the first post, we explain what a copy assignment operator is along with some C++ examples. https://learncplusplus.org/what-is-a-copy-assignment-operator-in-c/
What does the std:swap function do in C++?
The std::swap feature of modern C++ can be used to copy objects in C++. In the next post, we explain the typical declaration of a copy assignment operator with std::swap in C++ examples. https://learncplusplus.org/typical-declaration-of-a-copy-assignment-operator-with-stdswap/ We can copy properties of objects in C++ without std::swap too. In another article, we explain what the typical declaration of copy assignment operator without std::swap is along with some C++ examples. https://learncplusplus.org/typical-declaration-of-a-copy-assignment-operator-without-stdswap/
When you create a class in modern C++ it has copy assignment operator automatically. We can avoid the usage of this copy assignment operator in modern C++, to do this we use delete operator. In another post, we explain what we mean by “avoiding implicit copy assignment operator”, and how can we use the delete option with copy assignment in C++ examples. https://learncplusplus.org/what-is-avoiding-implicit-copy-assignment-in-c/
What is the rule of zero in C++?
Object Oriented Programming (OOP) is a way to integrate with objects which can contain data in the form ( attributes or properties of objects), and code blocks in the form of procedures ( methods , functions of objects). These attributes and methods are variables and functions that belong to the class – part of the class’s code and they are generally referred to as class members . Classes and structs are very useful in modern programming . There are some rules to support the principles of programming, one of which is the Rule of Zero in C++ . In the last post, we explain what is Rule of Zero in C++ with examples. https://learncplusplus.org/what-is-the-rule-of-zero-in-c/
How to learn modern C++ for free with examples?
LearnCPlusPlus.org has been producing full of educational daily articles about C and modern C++ that can be used with C++ Builder, C++ Builder CE, Dev-C++, BCC Compiler and some other compilers such as the GCC compiler. Here are our post picks for today.
What Is A Copy Assignment Operator in C++?
Typical Declaration Of A Copy Assignment Operator With std::swap
Typical Declaration Of A Copy Assignment Operator Without std::swap
What is Avoiding Implicit Copy Assignment In C++?
What Is The Rule of Zero in C++?
We like to hear your feedback . You motivate us so much with your likes and comments on social media (find us on Facebook, LinkedIn, Reddit, Twitter and all over) and here on the blogs too. Thank you for your valuable comments and questions. All of them help improve the quality of our future posts and new code in these posts.
We have a lot of unique posts waiting to come. We keep adding new topics every week about C++ in general and specific topics for C++ Builder, Dev-C++, and for the other C++ compilers. Please keep following our LearnCPlusPlus.org website for the latest posts and updates. Feel free to comment and share with your colleagues, students, members – knowledge is power, and knowledge shared is empowering.
What might be next for C++ Builder?
According to David Millington’s post, C++ Builder is aiming to include some amazing features; CLANG v15, support for C++20 and a lot of C++23 features, Win64 primary OS, new code completion, Visual Assist C++ navigation and refactoring, and lots more.
What’s Coming for C++Builder: An Amazing Preview
Note also that last month Embarcadero also announced the release of RAD Studio 11 Alexandria Release 3 , also known as RAD Studio 11.3, along with Delphi 11.3 and C++Builder 11.3. This release is focused on quality and improvements, building on the great new features in RAD Studio 11 Alexandria three previous releases.
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here . For professional developers, there are Professional, Architect, or Enterprise version.
About author
Yılmaz yörü, leave a reply cancel reply.
This site uses Akismet to reduce spam. Learn how your comment data is processed .
Join Our Global Developer Community
Join our email list and receive the latest case studies, event updates, product news, and much more.
- Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy. Start Free Trial Upgrade Today Free Delphi Community Edition Free C++Builder Community Edition
Something Fresh
Webstencils and htmx: free guide to fast web development, rad studio 12.2 athens inline patch 1 available, the untapped potential of ai in desktop applications: “power-charging” our delphi community, popular posts.
Announcing the Availability of RAD Studio 12.2 Athens
Delphi 12 and c++builder 12 community editions released, interbase odbc driver on github, embarcadero partners with raize software for ksvc maintenance.
- Toggle Reader Mode
Unknown Feed
Embarcadero’s users understand the scalability and stability of C++ and Delphi programming, and depend on the decades of innovation those languages bring to development. Ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero’s award-winning products over the past 30 years. Icons by Icons8.com .
© 2024 EMBARCADERO INC. ALL RIGHTS RESERVED
IMAGES
VIDEO
COMMENTS
For the formal copy assignment operator syntax, see function declaration. The syntax list below only demonstrates a subset of all valid copy assignment operator syntaxes.…
Copy constructor and Assignment operator are similar as they are both used to initialize one object using another object. But, there are some basic differences between them: …
Prerequisite: Operator Overloading The assignment operator,"=", is the operator used for Assignment. It copies the right value into the left value. Assignment Operators are predefined to operate only on built-in Data …
Assignment Operators in C Programming. Overview. In C programming, assignment operators are used to assign values to variables. The simple assignment …
c default constructed. c = a (copy assignment) The assignment operator works as expected in these cases. What about using the standard library? Assume adding the following …
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, …
The Copy Assignment Operator in a class is a non-template non-static member function that is declared with the “operator=“. This operator allows you to copy objects of classes, structs and unions.