0
Someone please explain this code
I want complete explanation of the output https://code.sololearn.com/c2sybx3q36Pb/?ref=app
4 Answers
+ 3
See this line?
return ~(partner * -1);
The tilde ~ here is bitwise NOT operator. Read about it below 👇
https://www.sololearn.com/learn/4076/?ref=app
When we apply arithmetic operation on a `char`, computer will use the ASCII code of the `char` as value for the arithmetic operation.
ASCII code for letter 'K' is 75, so the expression inside the parentheses
( partner * -1 )
Effectively inverts the sign of the ASCII code from (75) to (-75).
And next the bitwise NOT operator does its work, which inverts the sign of the result (-75) back into (75), and reduce it by one, so it results in (74), the ASCII code for character 'J'.
Hope it makes sense ...
+ 6
Letter before K?
Ans - J
+ 2
This program returns the letter / character that comes before the one you proved it.
For example: printf("%c", agentName('B'));
the program will output: A
Another example: printf("%c", agentName('5'));
the program will output: 4
+ 1
Carbon but can you explain me how it works. I know it outputs the preceding character but how? I don't understand the operation of this program