What is doing there only those who wrote the code can say. It may have been unintentionally. If it was by wanting the meaning it would be that she wants the next letter of the alphabet, skipping one, (technically the next character of the ASCII table extended) to what was picked up in that index. So as 4 is the index that has a v
the next character, skipping one, is the x
(I’m skipping one because the cont1
worth 2, if it was worth 1 would not need to skip one. I’m not saying that it will take the next element the array, This is done just on ex3[cont1 + 1]
.
You’re adding 2 to the number you find there.
I always say that, a lot of people don’t understand about graphic representation of a number.
The guy char
is a number like any other in which it is guaranteed to have 1 byte, so you can represent 256 different numbers. You can use this as the same number, it’s quiet, try printing with %d
instead of %c
.
When you take this data and have it printed with the formatter %c
instead of putting a text with the number worth there (actually a text of 1 to 3 characters only with numeric digits), it will print a single character based on an extended ASCII table, ie for each number has a corresponding graphic character.
Normal ASCII table (without the extended part which are characters ranging from 128 to 255):
Some characters are not exactly printable, or the print has a special way of handling, and has the number 0 which is the text terminator and not a valid character.
So when you get the v
that you see in your code, for the computer actually is only the number 118. When sum 2 it takes the 120 and in the table it is equivalent to the x
.
Do an experiment: change the letters inside the array by 5 numbers. Take the numbers by looking at the letters according to the table above. It is not so readable, but to that end it explains better what is happening.
You are only having the number 120 printed as a character of the ASCII table. If impri9mir only the number would print 120
(three characters composed of numerical digits). If you had them printed as a hexadecimal number then you would print 78
(again two characters) but this all does not change the number that for us who are accustomed to decimal is the 120. There in the table it still shows the octal shape or how is the entity of HTML, and could have other ways to represent a number.
It has many ways of representing numbers. I’m representing number 3, everyone knows it’s a 3 looking at it:
Thank you for the reply!
– Luiz Augusto