Talk:Increment and decrement operators: Difference between revisions

Content deleted Content added
No edit summary
suggest cleanup for example code
Line 9:
==Incorrect definition==
The article states that the "increment operator increases the value of its operand by 1", but this is only sometimes correct, and misses the point of the operator. The operator actually increases the value by an amount that reflects the number of machine words required to store the data. So if it's a character pointer on a byte-oriented machine, it increments by 1. If it's a pointer to a 4-byte int, then it increments by 4. If it's a pointer to a float on a machine that represents floating-point numbers in a single word, then it increments by 1, but on a modern byte-oriented machine it might increment it by 8. The point is, the compiler knows the size of the items and the machine's word-alignment requirements, and increments by the correct amount so the sense of the operation is always "step to the next thing". If the operand is an integer, then ++ steps to the next integer value, which is the same as adding 1, but this is only one narrow use case (which happens to be the one many people know about and use often). The article, as written, ignores the major value the operator has for programs that use pointers and structs. <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/199.27.168.23|199.27.168.23]] ([[User talk:199.27.168.23#top|talk]]) 02:43, 22 February 2018 (UTC)</small> <!--Autosigned by SineBot-->
 
 
==Sample code==
In the sample C code, the indices (i and n) should be of type unsigned rather than int