Issue
I am taking a course in operating systems and we were assigned the "Project 1 UNIX Shell and History Feature" as found in Abraham Silberschatz Operating Systems pg 157. I was doing research on the problem and came across an interesting GitHub code. It included an "else if" statement with an operator I've never seen before (a dash -). I'm trying to find out what it does.
(link)https://github.com/deepakavs/Unix-shell-and-history-feature-C/blob/master/shell2.c
else if (args[0][0]-'!' ==0)
{ int x = args[0][1]- '0';
int z = args[0][2]- '0';
as you can see in the two D array "ags[0][0]-'!'" and on "int x" and "int z"
Can someone tell me what this is called and what is it doing?
Thanks
Solution
args[0][1] - '0'
is the idiomatic way of converting a char
value which represents a digit to the numeric value of that digit. It works for all encodings supported by C.
args[0][0] - '!' == 0
is a flashy way of testing if args[0][0]
has the same value as '!'
. The author has an idiosyncratic, perhaps quixotic, sense of symmetry: most folk would write args[0][0] == '!'
.
Answered By - Bathsheba