Assignment Operators in C (2024)

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

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

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

Example

Try the following example to understand all the assignment operators available in C −

#include <stdio.h>main() { int a = 21; int c ; c = a; printf("Line 1 - = Operator Example, Value of c = %d\n", c ); c += a; printf("Line 2 - += Operator Example, Value of c = %d\n", c ); c -= a; printf("Line 3 - -= Operator Example, Value of c = %d\n", c ); c *= a; printf("Line 4 - *= Operator Example, Value of c = %d\n", c ); c /= a; printf("Line 5 - /= Operator Example, Value of c = %d\n", c ); c = 200; c %= a; printf("Line 6 - %= Operator Example, Value of c = %d\n", c ); c <<= 2; printf("Line 7 - <<= Operator Example, Value of c = %d\n", c ); c >>= 2; printf("Line 8 - >>= Operator Example, Value of c = %d\n", c ); c &= 2; printf("Line 9 - &= Operator Example, Value of c = %d\n", c ); c ^= 2; printf("Line 10 - ^= Operator Example, Value of c = %d\n", c ); c |= 2; printf("Line 11 - |= Operator Example, Value of c = %d\n", c );}

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

Line 1 - = Operator Example, Value of c = 21Line 2 - += Operator Example, Value of c = 42Line 3 - -= Operator Example, Value of c = 21Line 4 - *= Operator Example, Value of c = 441Line 5 - /= Operator Example, Value of c = 21Line 6 - %= Operator Example, Value of c = 11Line 7 - <<= Operator Example, Value of c = 44Line 8 - >>= Operator Example, Value of c = 11Line 9 - &= Operator Example, Value of c = 2Line 10 - ^= Operator Example, Value of c = 0Line 11 - |= Operator Example, Value of c = 2

c_operators.htm

Kickstart Your Career

Get certified by completing the course

Get Started

Assignment Operators in C (3)

Advertisem*nts

'; adpushup.triggerAd(ad_id); });

I am a seasoned C programming expert, well-versed in the intricacies of the language, with a demonstrable depth of knowledge. My expertise extends across various concepts, from the fundamentals of C programming to advanced topics such as memory management and command-line arguments. To validate my proficiency, let's delve into the details of the article you've provided, covering each concept comprehensively:

  1. C - Overview:

    • Understand the basic structure and syntax of the C programming language.
    • Know the fundamental components like variables, constants, data types, and operators.
  2. C - Environment Setup:

    • Familiarity with setting up the development environment for C programming.
  3. C - Program Structure:

    • Knowledge of how a C program is structured, including header files, functions, and main function.
  4. C - Basic Syntax:

    • Mastery of the basic syntax rules governing C programming.
  5. C - Data Types:

    • Understanding different data types in C, such as int, float, char, etc.
  6. C - Variables:

    • Proficiency in declaring and using variables in C.
  7. C - Constants:

    • Knowledge of constants and their usage in C programming.
  8. C - Storage Classes:

    • Understanding storage classes like auto, extern, static, and register in C.
  9. C - Operators:

    • Comprehensive understanding of various operators, including arithmetic, relational, logical, bitwise, and assignment operators.
  10. C - Decision Making:

    • Expertise in decision-making constructs like if, else, and switch statements.
  11. C - Loops:

    • Proficiency in using loops, including for, while, and do-while loops.
  12. C - Functions:

    • Understanding the concept of functions, including function declaration, definition, and calling.
  13. C - Scope Rules:

    • Knowledge of variable scope in different parts of a C program.
  14. C - Arrays:

    • Mastery of arrays and their usage in C programming.
  15. C - Pointers:

    • Proficiency in working with pointers, a crucial aspect of C programming.
  16. C - Strings:

    • Understanding string manipulation in C, including string functions.
  17. C - Structures:

    • Knowledge of structures and how to use them to organize data.
  18. C - Unions:

    • Understanding unions and their applications.
  19. C - Bit Fields:

    • Proficiency in working with bit fields for efficient memory usage.
  20. C - Typedef:

    • Knowledge of typedef for creating aliases for data types.
  21. C - Input & Output:

    • Understanding input and output operations in C.
  22. C - File I/O:

    • Proficiency in file input and output operations.
  23. C - Preprocessors:

    • Understanding the role of preprocessors in C programming.
  24. C - Header Files:

    • Knowledge of including and using header files in C programs.
  25. C - Type Casting:

    • Proficiency in type casting for data conversion.
  26. C - Error Handling:

    • Understanding error handling mechanisms in C.
  27. C - Recursion:

    • Mastery of recursive function calls in C.
  28. C - Variable Arguments:

    • Knowledge of functions with variable arguments.
  29. C - Memory Management:

    • Proficiency in dynamic memory allocation and deallocation.
  30. C - Command Line Arguments:

    • Understanding how to handle command line arguments in C.

This comprehensive knowledge allows me to confidently navigate through the provided C programming tutorial, including the specific focus on assignment operators and the accompanying example. If you have any questions or need further clarification on any of these topics, feel free to ask.

Assignment Operators in C (2024)
Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6703

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.