Compound Assignment Operator In C

'); doc.close(); function init(b, config) { b.addVar({ 'abTests[0][testName]': 'cssJsInjectionInlineLinkColor', 'abTests[0][bucketValue]': 3, 'abTests[1][testName]': 'indexUniversalWrapper', 'abTests[1][bucketValue]': 0, 'abTests[2][testName]': 'videoRangeToPlay', 'abTests[2][bucketValue]': 1, 'abTests[3][testName]': 'videoControls', 'abTests[3][bucketValue]': 1, 'abTests[4][testName]': 'cssJsInjection', 'abTests[4][bucketValue]': 0, 'ptax': 'tho_java-programming', 'tax0': 'tho', 'tax1': 'tho_sciences-math', 'tax2': 'tho_computer-science', 'tax3': 'tho_java-programming', 'tax4': '', 'templateId': '65', 'templateName': 'flexTemplate', 'templateView': 'PERSONAL_COMPUTER', 'tmog': 'g16212719d4e69702d31302d31342d392d39352d311b661', 'mint': 'g16212719d4e69702d31302d31342d392d39352d311b661', 'idstamp': 'g16212719d4e69702d31302d31342d392d39352d311b661', 'dataCenter': 'us-east-1', 'serverName': 'ip-10-14-9-95-1', 'serverVersion': '2.40.7', 'resourceVersion': '2.40.7', 'cc': 'UA', 'city': '', 'lat': '50.45', 'lon': '30.523', 'rg': '', 'clientTimestamp': new Date().getTime(), 'globeTimestamp': 1520727858510, 'referrer': document.referrer, 'sessionPc': '1', 'userAgent[familyName]': 'IE', 'userAgent[versionMajor]': '11', 'userAgent[versionMinor]': '0', 'userAgent[osName]': 'Windows 7', 'userAgent[osVersion]': '6.1', 'userAgent[mobile]': 'false', 'userAgent[raw]': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko' }); b.init({ beacon_url: 'https://rd.about.com/boomerang/reference', user_ip: '178.159.37.71', site_domain: 'thoughtco.com', BW: { enable: false }, DFPTiming: {} }); } if (document.addEventListener) { document.addEventListener("onBoomerangLoaded", function(e) { // e.detail.BOOMR is a reference to the BOOMR global object init(e.detail.BOOMR); }); } else if (document.attachEvent) { // IE 6, 7, 8 we use onPropertyChange and look for propertyName === "onBoomerangLoaded" document.attachEvent("onpropertychange", function(e) { if (!e) e=event; if (e.propertyName === "onBoomerangLoaded") { // e.detail.BOOMR is a reference to the BOOMR global object init(e.detail.BOOMR); } }); } })();(function() { var article = document.getElementById('article_1-0'); if (article && !article.gtmPageView) { article.gtmPageView = {"description":"Compound assignment operators provide a shorter syntax to assign the results of the arithmetic and bitwise operators.","errorType":"","updateDate":"2017-03-17","authorId":"47074","contentGroup":"Articles","documentId":2034054,"lastEditingAuthorId":"47074","lastEditingUserId":"148122552371372","characterCount":1102,"templateId":"65","socialTitle":"11 Ways to Tighten Your Java Code","title":"What Is a Compound-Assignment Operator?" || document.title || '',"currentPageOrdinal":"","previousPageOrdinal":"","entryType":"direct","pageviewType":"standard","templateVariation":"","publishDate":"2009-05-26","numOfImages":1,"numOfPages":1,"numOfArticleWords":"","numOfInlineLinks":"","excludeFromComscore":false,"socialImage":"https://fthmb.tqn.com/izSeldA8NcNJktPYaY8wt0Cczp4=/735x0/185124560-56a548563df78cf772876876.jpg","numOfMapLabels":"","isErrorPage":false,"instartLogicDelivered":0,"internalSessionId":"g16212719d4e69702d31302d31342d392d39352d311b661","internalRequestId":"g16212719d4e69702d31302d31342d392d39352d311b661","taxonomyNodes":[[{"documentId":4122478,"shortName":"ThoughtCo"},{"documentId":4132465,"shortName":"Science, Tech, Math"},{"documentId":4133486,"shortName":"Computer Science"},{"documentId":4133478,"shortName":"Java Programming"}]],"isCommerceDocument":false,"experienceTypeName":"","fullUrl":"https://www.thoughtco.com/compound-assignment-operator-2034054" + location.hash,"experienceType":"single page"}; } }()); (function() { Mntl.utilities.readyAndDeferred(function($container){ var $masonryInstance = $('#masonry-list1_1-0'); if ($masonryInstance.data('no-js')) return; Mntl.MasonryList.init($container, $masonryInstance, {stretch: '.card__img, .card--no-image .card__content'}); }); })();(function() { Mntl.utilities.readyAndDeferred(function($container){ var $masonryInstance = $('#masonry-list2_1-0'); if ($masonryInstance.data('no-js')) return; Mntl.MasonryList.init($container, $masonryInstance, {stretch: '.card__img, .card--no-image .card__content'}); }); })();

PrevNext

Assignment operators in C:

  • In C programs, values for the variables are assigned using assignment operators.
  • For example, if the value “10” is to be assigned for the variable “sum”, it can be assigned as “sum = 10;”
  • There are 2 categories of assignment operators in C language. They are,
    1. Simple assignment operator ( Example: = )
    2. Compound assignment operators ( Example: +=, -=, *=, /=, %=, &=, ^= )
sum = 10;
10 is assigned to variable sum
This is same as sum = sum + 10
This is same as sum = sum – 10
This is same as sum = sum * 10
This is same as sum = sum / 10
This is same as sum = sum % 10
This is same as sum = sum & 10
This is same as sum = sum ^ 10

Example program for C assignment operators:

  • In this program, values from 0 – 9 are summed up and total “45” is displayed as output.
  • Assignment operators such as “=” and “+=” are used in this program to assign the values and to sum up the values.

Output:

Continue on types of C operators:

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

Arithmetic_operatorsThese are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus
Assignment_operatorsThese are used to assign the values for the variables in C programs.
These operators are used to compare the value of two variables.
These operators are used to perform logical operations on the given two variables.
These operators are used to perform bit operations on given two variables.
Conditional operators return one value if condition is true and returns another value is condition is false.
These operators are used to either increase or decrease the value of the variable by one.
&, *, sizeof( ) and ternary operators.

PrevNext



# include <stdio.h>
Total+=i;// This is same as Total = Toatal+i
printf("Total = %d",Total);

0 Replies to “Compound Assignment Operator In C”

Lascia un Commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *