A
A
amalchikov2016-02-11 23:44:19
C++ / C#
amalchikov, 2016-02-11 23:44:19

What will be the result?

In the textbook I came across this part of the code:

char vlstr[SZ];
........
int k=vlstr[j]-'0';

What will be written in the variable k?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abcd0x00, 2016-02-12
@amalchikov

This is an ASCII calculation .
Each character in the set has its own position number (numbering from zero).
In ASCII, the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 are in order, so their numerical codes are in order - 48, 49, 50, 51, 52, 53, 54, 55 , 56, 57.
Whatever digital symbol we take, its value in numerical form can be found by subtracting the zero position from its position.
Most compilers are based on the ASCII table, but this is not fixed anywhere. If the compiler is based on another table, then this code may not work if the numbers in it are not next to each other or are not in order at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question