The Increment and Decrement Operators in C:
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:
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
. 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.
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
. 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.
Decrement:
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.
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.
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
[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
[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
Post a Comment