+ 4
Why is the answer f??
char x ='a'; cout<< char(x*5); please explain this code, came across in one of the quizes and im not getting why the answer is f. please help
7 odpowiedzi
+ 3
I ran this code and it printed the 'o' with the line in the top. If I did the x+5, I got the 'f'.
It multiplies the 'a' character number by 5 then prints it by character.
+ 3
thanks for answering but im still confused on this gues i need a full tutorial on chars
+ 3
chars have corresponding integer numbers, defined on the so called ASCII table.
They reach from 0 to 255.
Small 'a' is defined to 97.
So if you add 5 on it, it will be on place 102, and print f. The letters are assigned consecutively.
If you multiply, you will get a value greater than 255. But that is not a problem, the numbers repeat so to say.
If you know modulus, it's nothing else than the number mod 256.
So e.g. 256 will be 0 again, 257 will be 1, etc.
You can learn how it works in this assignment (and comments below it 😉)
https://www.sololearn.com/learn/6105/?ref=app
+ 2
Oviya arumugam Not in this case, since there is also an extended ASCII set.
97*5 = 485
485 mod 256 = 229
greek sigma
(But I think there was a plus in the quiz, otherwise it would be too complicated to know by heart)
One can easily check the table by printing it in a loop:
https://code.sololearn.com/cK9RQiYmaKoB/?ref=app
If you let it run double the length (i<512), you see the repeating pattern and small sigma on place 229 and 485.
+ 1
You are welcome
0
The ASCII value range is from 0-128
The multiply of a*5 is 485 .It does not have ASCII value
0
The output is black screen no output will show