#Meta-Wlp: #Macro: TITLE wlp: Learn C (III) p. 7
char * s,* t ;It is often confusing, this difference between char and char-star, that is, between a character and its reference. We highlight the difference by incrementing a character.
In the previous program, we incremented the reference to a character. The effect was to move forward to the next character in a string of characters.
Here we increment the character itself.
#include<stdio.h> int main(){ char * s ; s = "A" ; while ( (*s)<='Z' ) { /* for all letters from A to Z */ printf("%c ", *s ) ; /* insert newlines after G, P and W. */ if ( (*s=='G') || (*s=='P') || (*s=='W') ) printf("\n") ; /* insert the word "and" between Y and Z */ if ( *s=='Y' ) printf("and ") ; (*s) += 1 ; /* next letter */ } /* end-of-while */ printf("\nNow I've said my ABC's,\nTell me what you think of me.\n") ; }Try to guess when the logical expression,
(*s=='G') || (*s=='P') || (*s=='W')is true.
||
is the symbol for logical and. The expression
is true if all of its componenet subexpressions are true.
No letter is both a G, a P and a W at the same time, so there
are no newlines separating letters.
#:
The ||
is the symbol for logical or. The expression
is true if at least one of its component expressions is true.
There are newlines after the letters G, P and W.
#:
It is really impossible to say what the ||
does.
#: