MCS-011 Problem Solving and Programming

First year, Semester 1

Chapters

Newsletter

C Shorthand

C has a special shorthand that simplifies coding of certain type of assignment statements. For example:

a=a+2;

can be written as:

a += 2

The operator +=tells the compiler that a is assigned the value of a + 2; This shorthand works for all binary operators in C. The general form is:

variable operator = variable / constant / expression

These operators are listed below:

OperatorExampleMeaning
+=a += 2a = a + 2
-=a -= 2a = a - 2
*=a *= 2a = a * 2
/=a /= 2a = a / 2
%=a %= 2a = a % 2
&&=a &&= ca = a && c
||=a ||= ca = a || c

 
 

Report an issue

Reporting: C Shorthand (topic)

Related Posts