0

Can anyone explain how this code work and execute

plse https://code.sololearn.com/cIVw3ThG8A1t/?ref=app

13th Aug 2018, 1:38 PM
Programmer Raja
Programmer Raja - avatar
4 Answers
+ 5
Basically, it tests for an empty string. text is a 2D array of characters. If the following where given: text[t]="test"; *text[t] is the first 't'. Strings are ended with a '\0' or 0 byte. Booleans are true for non-zero values and false for zero. ! is the not unary operator. !*text[t] would be false for the string test above as 't' is true so !'t' is false. When text[t] is set to the empty string "", *text[t] is '\0' or false so !*text[t] is true.
15th Aug 2018, 4:28 PM
John Wells
John Wells - avatar
+ 5
It could have also been written: if(!text[t][0]) which would execute the exact same machine code. But, being 2 characters longer tends to be avoided even though it is so much clearer to other people.
15th Aug 2018, 4:37 PM
John Wells
John Wells - avatar
+ 4
As coded, it doesn't. It generates a compile error. If modified by moving line 16 to after line 20, it will work. It will output a prompt: enter the empty line to quit. It counts the lines it reads so entering: test tes te t gets 0 to 4 displayed. The strings get store in the array. Each of the characters in the strings gets a blank line outputted for it so 10 of them.
13th Aug 2018, 7:04 PM
John Wells
John Wells - avatar
+ 1
John can you explain what is this meaning if(!*text[t])
15th Aug 2018, 3:46 PM
Programmer Raja
Programmer Raja - avatar