The Increment and Decrement Operators in C:

The Increment Operator in C
    Figure 1:  The C symbol.

The Increment and Decrement Operators in C:

Introduction:

In C-derived programming languages, being able to increment and decrement number values is an extremely important skill.

The increment and decrement operations are deployed in loops etc., and whilst scripting videogames in suites such as Unity and Unreal – which use C#/JavaScript and C++ respectively – these operations are very often employed – amongst other things – to effect the motion of avatars and sprites and projectiles etc.

Body:

Operator Classification:

The Increment and Decrement operations are classed as unary operations, which means that the operator takes a single operand.

Example:

In an expression such as:

1++

, then the integer:

1

is considered the:

operand

or that which must be worked upon by the operator/operation; and the:

++

is considered the

operator

.  The complete expression:

1++

is considered to be:

the operation

.

Etymology:

The term, ‘increment’ is derived from the Latin noun, ‘incrēmentum,’[1].

An ‘incrēmentum’, in Latin, is ‘a growth,’ or ‘an increase.’  Etymologically, therefore, in the C programming language, we employ an increment so as to grow or increase a value by:

1

.

The term, ‘decrement’ is derived from the Latin noun, ‘dēcrēmentum,’[2].

A ‘dēcrēmentum’, in Latin, is ‘a diminution,’ or ‘a decrease.’  Etymologically, therefore, in the C programming language, we employ a decrement so as to diminish or to decrease a value by:

1

.

Increment:

Increment Operator (Cambria Math) An SVG rendering of the Increment Operator as found in the font, Cambria Math. The Raster Image that I based this Vector image upon was screenshotted at a font size of 510.
    Figure 2:  The Increment Operator.

Above is depicted the increment operator. It comprises two addition signs. When attempting to increment a value, we can place the increment operator to the left of the value:

++1

and this is termed:

prefixing[3]

. When we prefix an increment operator to our value, then this means that the value will be incremented, and only then will the value be used, or executed.

For instance, should be examine the statement in the pseudocode:

printf("%d,++1");

then we shall find that the value:

1

is incremented prior to its being printed.  Hence, the number:

2

is printed to the screen.

    Figure 3:  We have written a simple program that increments a variable, and then prints the value of that variable to the screen.

    Figure 4:  The output of the program as depicted in Figure 3.  2 is printed to the screen.

When attempting to increment a value, we can also place the increment operator to the right of the value:

1++

and this is termed:

postfixing[4].

. When we postfix an increment operator to our value, then this means that the value will be used or executed, and only then will the value be incremented.

For instance, should we examine the statement contained in the pseudocode:

printf("%d,1++");

then we shall find that the value:

1

is incremented after its being printed.  hence, the number:

1

is printed to the screen.

    Figure 5:  We have written a simple program that prints the value of a variable to a screen, and then increments the value of the variable.

    Figure 6:  The output of the program as depicted in Figure 5.  1 is printed to the screen.

Decrement:

Decrement Operator Cambria Math This decrement operator was screen-captured at the fontsize of 510
    Figure 7:  The decrement operator.

Above is depicted the decrement operator. It comprises two subtraction signs. When attempting to decrement a value, we can place the decrement operator to the left of the value:

--1

and this is termed:

prefixing

. When we prefix a decrement operator to our value, then this means that the value will be decremented, and only then will the value be used, or executed.

For instance, should be examine the statement in the pseudocode:

printf("%d,--1");

then we shall find that the value:

1

is decremented prior to its being printed.  Hence, the number:

0

is printed to the screen.

    Figure 8:  We have written a simple program that decrements the value of a variable, and then prints the value of that variable to the screen.

    Figure 9:  The output of the program as depicted in Figure 8.  0 is printed to the screen.

When attempting to decrement a value, we can also place the decrement operator to the right of the value:

1--

and this is termed:

postfixing

. When we postfix a decrement operator to our value, then this means that the value will be used or executed, and only then will the value be decremented.

For instance, should be examine the statement in the pseudocode:

printf("%d,1--");

then we shall find that the value:

1

is printed prior to its being decremented.  Hence, the number:

1

is printed to the screen.


    Figure 10:  We have written a simple program that prints the value of a variable to the screen, and then decrements the value of that variable.

    Figure 11:  The output of the program as depicted in Figure 10.  1 is printed to the screen.

Conclusion:

Knowing how to increment and decrement numbers is an important skill, that one must master in his/her programming career.  Incrementation and Decrementation – especially when it comes to C-derived programming languages – possesses a wide number of applications: there are quite a number of computational problems that can be solved with the aid of the increment and decrement operations.


[1].  ‘incrēmentum, incrēmentī’2nd-declension neuter noun, ‘growth,’ ‘development,’ ‘increase,‘ ‘augmentation,’ ‘increment.’  Further derived from the Latin preposition, ‘in,’ which – in this instance – means ‘unto;’ and the Latin 3rd-conjugation verb, ‘crēscō, crēcere, crēvī, crētum,’ which means ’ ‘to increase,’ ‘to grow,’ ‘to augment.’  Etymologically, therefore, we employ an increment – such as x++unto the increase (by the magnitude of 1) of our value.

[2].  ‘dēcrēmentum, dēcrēmentī’2nd-declension neuter noun, ‘diminution,’ ‘decrease.’  Further derived from the Latin preposition, ‘dē,’ which – in this instance – means ‘reversal;’ and the Latin 3rd-conjugation verb, ‘crēscō, crēcere, crēvī, crētum,’ which means ’ ‘to increase,’ ‘to grow,’ ‘to augment.’  Etymologically, therefore, we employ a decrement – such as x-- – so as to reverse-increase – or to decrease – our value by a magnitude of 1.

[3].  The English noun, ‘prefix’ is derived from the latin preposition, ‘prae,’ which means ‘before;’ and the Latin 3rd-conjugation verb, ‘fīgō, fīgere, fīgī fīxum,’ which means ‘to fasten,’ ‘to affix,’ ‘to fix.’  Etymologically, therefore, unary operators are said to be affixed to or fastened on to their operands. Should the unary operator be affixed to the left-hand side of the operand, then this is termed ‘a prefix,’ whereas should the unary operator be affixed to the righthand side of the operand, then this is termed ‘a postfix.’

[4].  The English noun, ‘postfix’ is derived from the latin preposition, ‘post,’ which means ‘after;’ and the Latin 3rd-conjugation verb, ‘fīgō, fīgere, fīgī fīxum,’ which means ‘to fasten,’ ‘to fix.’  Etymologically, therefore, unary operators are said to be affixed to or fastened on to their operands. Should the unary operator be affixed to the left-hand side of the operand, then this is termed ‘a prefix,’ whereas should the unary operator be affixed to the righthand side of the operand, then this is termed ‘a postfix.’

Comments

Popular posts from this blog

An Introduction to Modern Geometry: The Directed Line Segment