certificatebadge

Assignment Operators in C

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.

Introduction

Assignment Operators help us to assign the value or result of an expression to a variable and the value on the right side must be of the same data type as the variable on the left side. They have the lowest precedence level among all the operators, and it associates from right to left. The most commonly used Assignment Operator is = . Also, Assignment Operators fall under the category of Binary Operators.

For example, x = 4 ; then that means value 4 is assigned to variable x or we can say that variable x holds value 4 .

Explanation

Let me explain to you more about Assignment Operators. Don't worry after this section, you will fully understand the definition of Assignment Operators in C.

Our example is x = 4 , so what does it tell us?

So can we say that always variables are on the Left Hand Side of the assignment operator and values are always on the Right Hand Side of the operator? YES . Please take a look at the image it will help you to understand more about the above wording.

LHS and RHS Operands

The above diagram helps us to understand that the RHS value is assigned to the LHS variable.

The LHS and RHS are known as Operands.

So the operand on the LHS of the assignment operator must be a variable and operand on RHS must be a constant , variable or expression . For example:

As mentioned, precedence levels of assignment operators are lower than all the operators we have discussed so far and it associates from right to left. Now you may wonder what do you mean by it associates from right to left? Let's understand this together.

For example:

This is totally correct and means we can also assign the same value to multiple variables with one single line of code .

So what do you get from the above line of code? Simply, variable_x , variable_y and variable_z hold the same value. YES!! TRUE. But how?

The main question is here how value is assigned to them? is first variable_x get 10 or variable_y or variable_z ? What do you say? This answer is given by the line: It associates from right to left .

So that means we have to read the line from the right side to the left. Like, at first 10 is given to variable_z then variable_y gets the value present in the variable_z and after that variable_x get the value present in the variable_y . So the above wording is equivalent to the following expression.

This is the simplest explanation about assignment operator associativity.

The most basic Assignment operator is = . It requires two operands for its work. For example, = x doesn't make any sense but variable = x makes sense because it clearly says the variable variable stores the value of x . Therefore, Assignment operators are Binary operators.

Hopefully, every point in the definition is now clear to all of you.

List of All Assignment Operators in C

We have 2 types of Assignment Operators in C :

Simple Assignment Operator in C

It is the operator used to assign the Right Operand to Left Operand . There is only one simple Assignment Operator and that is = . The general Syntax is like Left Operand = Right Operand .

Compound Assignment Operators in C

Any Binary Operator with a simple Assignment Operator will form Compound Assignment Operators.

The general syntax is like Left operand operation = Right operand . Here, the operation is what you want + , - , *, etc.

Let's take an example:

Here read carefully. After which, you will never forget how to read the syntax of a compound assignment operator.

So we read like this FIRST ADD 10 to variable_x , THEN WHATEVER THE RESULT, ASSIGN THAT RESULT TO variable_x . That means the above line of code is equal to

List 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 program for Assignment Operators in C

This is a simple Assignment Operator.

+= Operator

This is the Addition Assignment Operator . In which the left operand becomes equal to the addition of the right operand and left operand.

In this program, x+=y means x+y , so we assign the result of x+y to x .

-= Operator

This is the Subtraction Assignment Operator .

In which left operand becomes equal to the subtraction of right operator from left operand.

The program performs the subtraction of two numbers i.e. x-=y means x = x-y . So the output is :

*= Operator

The main purpose of this operator is that this left operand becomes equal to the product of the left and right operand. This is the Multiplication Assignment Operator .

The program performs the multiplication of two numbers and then the result of the multiplication is assigned to the variable x .

/= Operator

This one is Division Assignment Operator . In this, the left operand becomes equal to the division of the left and right operand.

This program performs a division of two numbers and the result is assigned to x variable i.e. x/=y is the same as x = x/y .

%= Operator

It is well known Modulus Assignment Operator . In this , left operand becomes equal to the modulo of left and right operand.

In this program, the user checks the remainder of two number and assign that remainder to x variable.

<<= Operator

This is called the Left Shift Assignment Operator . For example x <<= y so in this, x becomes equal to x left shifted by y .

The program basically shifts every bit of x to the left side by y places and then assigns the result to x .

>>= Operator

This is called the Right Shift Assignment Operator . For example x >>= y so , x becomes equal to x right shifted by y .

The program has defined the result of expression when x is right-shifted by y places and the result is going to store in x variable.

&= Operator

This operator is called the Bitwise AND Assignment Operator . Left operand becomes equal to the bitwise AND of left and right operand.

The program performs Bitwise AND operation on every bit of x and y . After that result is going to be stored in variable x .

|= Operator

This is called the Bitwise Inclusive OR Assignment Operator Left operand becomes equal to bitwise OR of left and right operand.

like Bitwise AND Assignment Operator , this program also performs Bitwise OR operation on every bit of x and y . And after that result is going to store in x .

^= Operator

This is called the Bitwise Exclusive OR Assignment Operator Left operand becomes equal to bitwise XOR of left and right operand.

This will perform Bitwise XOR operation on every bit of x and y . After that result is going to store in x .

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

Happy Coding folks!!!

certificate icon

C – Assignment Operators

  prev       next, assignment operators in c:.

In C programs, values for the variables are assigned using assignment operators.

Example program for C assignment operators:

Continue on types of C operators:

Click on each operator name below for detailed description and example programs.

Prev       Next

Javatpoint Logo

C Control Statements

C functions, c dynamic memory, c structure union, c file handling, c preprocessor, c command line, c programming test, c interview.

JavaTpoint

Help Others, Please Share

facebook

Learn Latest Tutorials

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on [email protected] , to get more information about given services.

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected] Duration: 1 week to 2 week

RSS Feed

C++ Tutorial

C++ functions, c++ classes, c++ examples, c++ assignment operators, 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:

Get started with your own server with Dynamic Spaces

COLOR PICKER

colorpicker

Get your certification today!

assignment operators in c with example program

Get certified by completing a course today!

Subscribe

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]

Your Suggestion:

Thank you for helping us.

Your message has been sent to W3Schools.

Top Tutorials

Top references, top examples, web certificates, get certified.

Learn C++ interactively.

Learn C++ practically and Get Certified .

Popular Tutorials

Popular examples, reference materials.

Learn C++ Interactively

Interactive C++ Course

C++ introduction.

C++ Flow Control

C++ Arrays & String

C++ Object & Class

Related Topics

C++ Vectors

C++ Unordered Set

C++ STL Containers

In this tutorial, we will learn about C++ STL List and its functions with the help of examples.

C++ List is a STL container that stores elements randomly in unrelated locations. To maintain sequential ordering, every list element includes two links:

C++ STL  list implementation showing its doubly linked nature

In C++, the STL list implements the doubly-linked list data structure . As a result, we can iterate both forward and backward.

To create a list, we need to include the list header file in our program.

Once we import the header file, we can now declare a list using the following syntax:

Let's see an example,

Note: We can also include list elements without mentioning the assignment operator. For example,

In the above example, we have created a list named numbers with elements: 1 , 2 , 3 , 4 . We then used a ranged for loop to print the list elements.

Note: We have used list instead of std::list because we have already defined std namespace using using namespace std; .

C++ STL provides various functions that we can use to perform different operations on lists. Let's look at some commonly used list functions to perform the following operations:

1. Add Elements to a List in C++

We can add values in a list using the following functions:

2. Access List Elements

We can access list elements using the following functions:

3. Delete List Elements

We can delete list elements using the following functions:

Here's an example,

While there are many functions that can be used with lists, we will only look at some of the functions in the table below:

We can use iterators to access a list element at a specified position. For example,

In the above example,

Notice that we have used ++itr; repeatedly instead of adding an integer to itr like itr+3; .

This is because iterators are not simple numeric values like regular integers. They point to specific memory locations in the container. Incrementing an iterator with the ++ operator makes it point to the next element in the container.

To learn more about iterators, visit C++ STL Iterators .

Frequently Asked Questions

We use the insert() function to add an element at a specified position.

The syntax for insert() function for list is:

We use remove() function to remove an element at a specified position.The syntax of remove() function is:

The remove() function can be used in the following two ways:

1. remove() using Value

2. remove() using iterator

Here, both elements with a value of 3 are deleted, even though we only used remove() function on the fourth element.

This is because the remove() function removes all the elements having the same value as the element pointed by the iterator.

Table of Contents

Sorry about that.

Related Tutorials

C++ Tutorial

Try PRO for FREE

Related Articles

C++ Assignment Operator Overloading

Prerequisite: Operator Overloading

The assignment operator,”=”, is the operator used for Assignment. It copies the right value into the left value. Assignment Operators are predefined to operate only on built-in Data types.

We can’t directly use the Assignment Operator on objects. The simple explanation for this is that the Assignment Operator is predefined to operate only on built-in Data types. As the class and objects are user-defined data types, so the compiler generates an error.

here, a and b are of type integer, which is a built-in data type. Assignment Operator can be used directly on built-in data types.

c1 and c2 are variables of type “class C”. Here compiler will generate an error as we are trying to use an Assignment Operator on user-defined data types.

The above example can be done by implementing methods or functions inside the class, but we choose operator overloading instead. The reason for this is, operator overloading gives the functionality to use the operator directly which makes code easy to understand, and even code size decreases because of it. Also, operator overloading does not affect the normal working of the operator but provides extra functionality to it.

Now, if the user wants to use the assignment operator “=” to assign the value of the class variable to another class variable then the user has to redefine the meaning of the assignment operator “=”.  Redefining the meaning of operators really does not change their original meaning, instead, they have been given additional meaning along with their existing ones.

Please Login to comment...

Improve your Coding Skills with Practice

Start your coding journey now.

The Simple Assignment Operator

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

Precedence and Associativity

Abbreviated Assignment Operators

Auto Increment and Auto Decrement

EDUCBA

Assignment Operators in C

Priya Pedamkar

Introduction to Assignment Operators in C

Assignment operators are used for assigning value to the variable. Like any other operator, C also supports Assignment Operator which is a binary operator that operates on any two operands. It has 2 values such as the right value and the left value. It has lower precedence than all available operators but has higher precedence than the comma operator.

Course Curriculum

Different List of Assignment Operators in C

Below is the list of Assignment operators in C

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

There are many other assignment operators such as Left shift AND (<<=) operator, Right shift AND operator (>>=), Bitwise AND assignment operator (&= ), Bitwise exclusive OR and assignment operator (^=), Bitwise inclusive OR and assignment operator(|=)

Examples of Assignment Operators in C

Examples of Assignment Operators are given below:

Program to implement the use of = operator:

Assignment operators- example1

Program to implement the use of Add AND operator (+=) in C:

Assignment Operators- example2

Program to use Subtract AND operator (- =) in C:

Assignment Operators- example3

Program to use Multiply AND operator (*=) in C:

Assignment Operators- example4

Program to use Divide AND operator (/=) in C:

Assignment Operators- example5

Program to use Modulus AND operator (%=) in C

Modulus AND operator- example6

Program to use Left shift AND (<<=) operator in C

Left shift AND - example7

Program to use Right shift AND (>>=) operator in C

Right shift AND - example8

Program to use Bitwise AND assignment operator (&= ) in C

 Bitwise AND - example9

Example #10

Program to use Bitwise exclusive OR and assignment operator (^=)

Bitwise exclusive OR- example10

Example #11

Program to use Bitwise inclusive OR and assignment operator (|=) in C

Bitwise inclusive OR - example11

Recommended Articles

This is a guide to Assignment Operators in C. Here we discuss different list of Assignment Operators in C along with the examples. You can also go through our other suggested articles to learn more –

Sale

Related Courses

EDUCBA

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

By signing up, you agree to our Terms of Use and Privacy Policy .

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Quiz

Explore 1000+ varieties of Mock tests View more

Submit Next Question

quiz

Assignment Operators in C

Top Banner

We use this type of operator to transform as well as assign the values to any variable in an operation. In any given assignment operator, the right side is a value, and the left side is a variable. The value present on the right side of the operator must have the same data type as that of the variable present on the left side. In any other case, the compiler raises an error.

In this article, we will take a look into the Assignment Operators in C according to the GATE Syllabus for CSE (Computer Science Engineering) . Read ahead to know more.

Table of Contents

Types of Assignment Operators in C

An assignment operator is basically a binary operator that helps in modifying the variable to its left with the use of the value to its right. We utilize the assignment operators to transform and assign values to any variables.

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

Working of Assignment Operators in C

Here is a table that discusses, in brief, all the Assignment operators that the C language supports:

Example of Assignment Operators in C

Let us look at an example to understand how these work in a code:

#include <stdio.h>

int x = 21;

printf(“Line A – = Example of the Value of y = %d\n”, y );

printf(“Line B – -= Example of the Value of y = %d\n”, y );

printf(“Line C – += Example of the Value of c = %d\n”, c );

printf(“Line D – /= Example of the Value of y = %d\n”, y );

printf(“Line E – *= Example of the Value of y = %d\n”, y );

y <<= 2;

printf(“Line F – <<= Example of the Value of y = %d\n”, y );

printf(“Line G – %= Example of the Value of y = %d\n”, y );

y &= 2;

printf(“Line H – &= Example of the Value of y = %d\n”, y );

y >>= 2;

printf(“Line I – >>= Example of the Value of y = %d\n”, y );

printf(“Line J – |= Example of the Value of y = %d\n”, y );

printf(“Line K – ^= Example of the Value of y = %d\n”, y );

The compilation and execution of the program mentioned above will produce a result as follows:

Line A – = Example of the Value of y = 21

Line B – -= Example of the Value of y = 21

Line C – += Example of the Value of y = 42

Line D – /= Example of the Value of y = 21

Line E – *= Example of the Value of y = 441

Line F – <<= Example of the Value of y = 44

Line G – %= Example of the Value of y = 11

Line H – &= Example of the Value of y = 2

Line I – >>= Example of the Value of y = 11

Line J – |= Example of the Value of y = 2

Line K – ^= Example of the Value of y = 0

Here is another example of how the assignment operators work in the C language:

int y = 10;

printf(“z = x + y = %d \n”,z);

printf(“z += x = %d \n”,z);

printf(“z -= x = %d \n”,z);

printf(“z *= x = %d \n”,z);

printf(“z /= x = %d \n”,z);

printf(“z %= x = %d \n”,z);

c &= x ;

printf(“c &= x = %d \n”,z);

printf(“z ^= x = %d \n”,z);

printf(“z |= x = %d \n”,z);

z <<= 2 ;

printf(“z <<= 2 = %d \n”,z);

z >>= 2 ;

printf(“z >>= 2 = %d \n”,z);

The output generated here will be:

z = x + y = 15

z += x = 20

z -= x = 15

z *= x = 75

z &= x = 0

z ^= x = 10

z |= x = 10

z <<= 2 = 40

z >>= 2 = 10

z >>= 2 = 2

Practice Problems on Assignment Operators in C

1. What would be the output obtained from the program given below?

#include<stdio.h>

p += p += p += 3;

printf(“%d”,p);

Answer – A. 20

p+=p+=p+=3; it can written as p+=p+=p=p+3; p=2; Or, p+=p+=5; p=5; Or, p+=p=5+5; p=5; Or, p+=10; p=10; Or, p=p+10; p=10; Or, p=20. So, finally p=20.

2. Which of these is an invalid type of assignment operator?

D. None of these

Answer – D. None of these

All of these are valid types of assignment operators.

How does the /= operator work? Is it a combination of two other operators?

Yes, the /+ operator is a combination of the = and / operators. The / operator divides the current value of the available variable first on the left using the available value on the right. It then assigns the obtained result to the available variable on the left side.

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

The = operator is the most basic one used in the C language. We use this operator to assign the value available in the right to the value mentioned on the left side of the operator.

Keep learning and stay tuned to get the latest updates on  GATE Exam  along with  GATE Eligibility Criteria ,  GATE 2023 ,  GATE Admit Card ,  GATE Syllabus for CSE (Computer Science Engineering) ,  GATE CSE Notes ,  GATE CSE Question Paper , and more.

Also Explore,

Leave a Comment Cancel reply

Your Mobile number and Email id will not be published. Required fields are marked *

Request OTP on Voice Call

Post Comment

assignment operators in c with example program

Connect with us for GATE Preparation

Register now to get complete assistance for the gate 2022 exam.

Register with BYJU'S & Download Free PDFs

Conditional Operator in C ( ?: ) with Example

Please enable JavaScript

What is a Conditional Operator in C

Syntax of conditional operator in c, conditional operator example, more example of conditional operator in c, more than one conditional operator in a statement, conditional operator in c for three variables, choose a c conditional operator from the list, choose a syntax for c ternary operator from the list.

Q7) What is the other name for the conditional operator? The other name for the conditional operator is the ternary operator.

if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'knowprogram_com-leader-3','ezslot_17',117,'0','0'])};__ez_fad_position('div-gpt-ad-knowprogram_com-leader-3-0'); if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'knowprogram_com-leader-3','ezslot_18',117,'0','1'])};__ez_fad_position('div-gpt-ad-knowprogram_com-leader-3-0_1'); if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'knowprogram_com-leader-3','ezslot_19',117,'0','2'])};__ez_fad_position('div-gpt-ad-knowprogram_com-leader-3-0_2'); .leader-3-multi-117{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:15px!important;margin-left:auto!important;margin-right:auto!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important} Leave a Comment Cancel Reply

IncludeHelp_logo

IncludeHelp

Home » C Popular & Interesting Questions

What is the difference between = (Assignment) and == (Equal to) operators in C?

Difference between assignment (=) vs equal to (==) operators in c.

Many times this question arises what is the difference between = and == operators in C programming language? Here we are going to tell you exactly what the differences between these two operators are.

Assignment Operator (=)

= is an Assignment Operator in C, C++ and other programming languages, It is Binary Operator which operates on two operands.

= assigns the value of right side expression’s or variable’s value to the left side variable.

Let's understand by example:

Here, When first expression evaluates value of (a+b) will be assigned into x and in second expression y=x; value of variable x will be assigned into y .

Equal To Operator (==)

== is an Equal To Operator in C and C++ only, It is Binary Operator which operates on two operands.

== compares value of left and side expressions, return 1 if they are equal other will it will return 0.

When expression x==y evaluates, it will return 1 (it means condition is TRUE ) and "TRUE" will print.

So it's cleared now, , both are not same , = is an Assignment Operator it is used to assign the value of variable or expression, while == is an Equal to Operator and it is a relation operator used for comparison (to compare value of both left and right side operands).

Preparation

What's New (MCQs)

Top Interview Coding Problems/Challenges!

Comments and Discussions!

IncludeHelp's Blogs

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML Solved programs: » C » C++ » DS » Java » C# Aptitude que. & ans.: » C » C++ » Java » DBMS Interview que. & ans.: » C » Embedded C » Java » SEO » HR CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS More: » Articles » Puzzles » News/Updates

ABOUT SECTION » About us » Contact us » Feedback » Privacy policy

STUDENT'S SECTION » Internship » Certificates » Content Writers of the Month

SUBSCRIBE » Facebook » LinkedIn » Subscribe through email

© https://www.includehelp.com some rights reserved.

Learn coding interactively.

Popular tutorials, learn python interactively, popular examples, introduction.

C# Operators

Flow Control

Additional Topics

Related Topics

C# Bitwise and Bit Shift Operators

C# Operator Precedence and Associativity

C# ternary (? :) Operator

C# Basic Input and Output

In this article, we will learn everything about different types of operators in C# programming language and how to use them.

Operators are symbols that are used to perform operations on operands. Operands may be variables and/or constants.

For example , in 2+3 , + is an operator that is used to carry out addition operation, while 2 and 3 are operands.

Operators are used to manipulate variables and values in a program. C# supports a number of operators that are classified based on the type of operations they perform.

1. Basic Assignment Operator

Basic assignment operator (=) is used to assign values to variables. For example,

Here, 50.05 is assigned to x.

Example 1: Basic Assignment Operator

When we run the program, the output will be:

This is a simple example that demonstrates the use of assignment operator.

You might have noticed the use of curly brackets { } in the example. We will discuss about them in string formatting . For now, just keep in mind that {0} is replaced by the first variable that follows the string, {1} is replaced by the second variable and so on.

2. Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, etc.

For example,

Example 2: Arithmetic Operators

Arithmetic operations are carried out in the above example. Variables can be replaced by constants in the statements. For example,

3. Relational Operators

Relational operators are used to check the relationship between two operands. If the relationship is true the result will be true , otherwise it will result in false .

Relational operators are used in decision making and loops.

Example 3: Relational Operators

4. logical operators.

Logical operators are used to perform logical operation such as and , or . Logical operators operates on boolean expressions ( true and false ) and returns boolean values. Logical operators are used in decision making and loops.

Here is how the result is evaluated for logical AND and OR operators.

In simple words, the table can be summarized as:

Example 4: Logical Operators

5. unary operators.

Unlike other operators, the unary operators operates on a single operand.

Example 5: Unary Operators

The increment (++) and decrement (--) operators can be used as prefix and postfix. If used as prefix, the change in value of variable is seen on the same line and if used as postfix, the change in value of variable is seen on the next line. This will be clear by the example below.

Example 6: Post and Pre Increment operators in C#

We can see the effect of using ++ as prefix and postfix. When ++ is used after the operand, the value is first evaluated and then it is incremented by 1 . Hence the statement

prints 10 instead of 11 . After the value is printed, the value of number is incremented by 1 .

The process is opposite when ++ is used as prefix. The value is incremented before printing. Hence the statement

prints 12 .

The case is same for decrement operator (--) .

6. Ternary Operator

The ternary operator ? : operates on three operands. It is a shorthand for if-then-else statement. Ternary operator can be used as follows:

The ternary operator works as follows:

Example 7: Ternary Operator

To learn more, visit C# ternary operator .

7. Bitwise and Bit Shift Operators

Bitwise and bit shift operators are used to perform bit manipulation operations.

Example 8: Bitwise and Bit Shift Operator

To learn more, visit C# Bitwise and Bit Shift operator .

8. Compound Assignment Operators

Example 9: compound assignment operator.

We will discuss about Lambda operators in later tutorial.

Table of Contents

Sorry about that.

Related Tutorials

C# Tutorial

IMAGES

  1. Arithmetic Operator In C++

    assignment operators in c with example program

  2. Assignment Operators in C/C++

    assignment operators in c with example program

  3. assignment-operators

    assignment operators in c with example program

  4. Programming in C

    assignment operators in c with example program

  5. C Programming Tutorial

    assignment operators in c with example program

  6. 😍 Assignment operator in c. Operators in C and C++. 2019-02-14

    assignment operators in c with example program

VIDEO

  1. Assignment operator in C

  2. Operators in C

  3. Assignment Operator in C Programming

  4. Assignment operator in C

  5. C Programming

  6. C++ Operators

COMMENTS

  1. Assignment Operators in C/C++

    Different types of assignment operators are shown below: "=": This is the simplest assignment operator. 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'; "+=": This operator is combination of '+' and '=' operators.

  2. Assignment Operators in C

    Line 1 - = Operator Example, Value of c = 21 Line 2 - += Operator Example, Value of c = 42 Line 3 - -= Operator Example, Value of c = 21 Line 4 - *= Operator Example, Value of c = 441 Line 5 - /= Operator Example, Value of c = 21 Line 6 - %= Operator Example, Value of c = 11 Line 7 - >= Operator Example, Value of c = 11 Line 9 - &= Operator …

  3. Assignment Operators in C Example

    The Assignment operators in C are some of the Programming operators that are useful for assigning the values to the declared variables. Equals (=) operator is the most commonly used assignment operator. For example: int i = 10; The below table displays all the assignment operators present in C Programming with an example.

  4. Assignment Operators in C

    We have 2 types of Assignment Operators in C : Simple Assignment operator (Example : = ). Compound Assignment Operators (Example : += , -= , &= ). Simple Assignment Operator in C It is the operator used to assign the Right Operand to Left Operand. There is only one simple Assignment Operator and that is = .

  5. Assignment operators in C

    There are 2 categories of assignment operators in C language. They are, 1. Simple assignment operator ( Example: = ) 2. Compound assignment operators ( Example: +=, -=, *=, /=, %=, &=, ^= ) Example program for C assignment operators: In this program, values from 0 - 9 are summed up and total "45" is displayed as output.

  6. Operators in C

    Example 1: Arithmetic Operators // Working of arithmetic operators #include <stdio.h> int main() { int a = 9,b = 4, c; c = a+b; printf("a+b = %d \n",c); c = a-b; printf("a-b = %d \n",c); c = a*b; printf("a*b = %d \n",c); c = a/b; printf("a/b = %d \n",c); c = a%b; printf("Remainder when a divided by b = %d \n",c); return 0; } Run Code Output

  7. Operators In C

    For example, + and - are the operators to perform addition and subtraction in any C program. C has many operators that almost perform all types of operations. These operators are really useful and can be used to perform every operation. Additionally, you can also learn more about the uses of C language. Basics to Advanced - Learn It All!

  8. Assignment Operator in C

    The assignment operator is used to assign the value, variable and function to another variable. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. Example of the Assignment Operators: A = 5; // use Assignment symbol to assign 5 to the operand A B = A; // Assign operand A to the B

  9. C++ Assignment Operators

    Assignment operators are used to assign values to variables. In the example below, we use the assignment operator ( =) to assign the value 10 to a variable called x: Example int x = 10; Try it Yourself » The addition assignment operator ( +=) adds a value to a variable: Example int x = 10; x += 5; Try it Yourself »

  10. C++ List (With Examples)

    C++ List is a STL container that stores elements randomly in unrelated locations. To maintain sequential ordering, every list element includes two links: one that points to the previous element; another that points to the next element; C++ STL list implementation. In C++, the STL list implements the doubly-linked list data structure. As a ...

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

  12. 🔥🔥Assignment Operators and Shorthand Operator in C Programming

    👇Assignment Operators and Shorthand Operator in C Programming - In Hindi - Tutorial#5C-Program Playlist - https://youtube.com/playlist...

  13. C Programming Course Notes

    Introduction to C Programming Operators 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 ). Note the following examples:

  14. PDF C

    Assignment Operators There are following assignment operators supported by C language: Show Examples Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C += Add AND assignment operator, It adds right

  15. Different List of Assignment Operators in C

    Examples of Assignment Operators are given below: Example #1 Program to implement the use of = operator: Code: #include<stdio.h> #include<conio.h> int main() { int X, Y, total; printf("Enter the value of X: "); scanf("%d",& X); printf("Enter the value of Y: "); scanf("%d",& Y); total = X + Y; printf("%d", total); return 0; } Output: Example #2

  16. Assignment Operators in C Programming

    In this C Programming Video Tutorial we will learn about assignment operators in detail.Operators are the symbol which will perform different operation on th...

  17. Assignment Operators in C

    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 ( &= )

  18. Conditional Operator in C ( ?: ) with Example

    The conditional operator in C is a conditional statement that returns the first value if the condition is true and returns another value if the condition is false. It is similar to the if-else statement. The if-else statement takes more than one line of the statements, but the conditional operator finishes the same task in a single statement.

  19. Difference between Assignment (=) Vs Equal to (==) Operators in C

    Assignment Operator (=) = is an Assignment Operator in C, C++ and other programming languages, It is Binary Operator which operates on two operands. = assigns the value of right side expression's or variable's value to the left side variable. Let's understand by example: x = (a + b); y = x;

  20. Bitwise operations in C

    Example: a simple addition program. The following program adds two operands using AND, XOR and left shift (<<). ... Bitwise assignment operators. C provides a compound assignment operator for each binary arithmetic and bitwise operation. Each operator accepts a left operand and a right operand, performs the appropriate binary operation on both ...

  21. C# Operators: Arithmetic, Comparison, Logical and more

    Operators are used to manipulate variables and values in a program. C# supports a number of operators that are classified based on the type of operations they perform. 1. Basic Assignment Operator. Basic assignment operator (=) is used to assign values to variables. For example, double x; x = 50.05; Here, 50.05 is assigned to x.