Computer Science Canada [C] strcmp vs. dereference and == |
Author: | Cervantes [ Thu Jun 29, 2006 8:37 am ] | ||||
Post subject: | [C] strcmp vs. dereference and == | ||||
Is there any advantage to using strcmp over dereferencing the pointers and comparing with ==?
vs.
Both output the "Hello\n". Both output the "Hello\n" even if I allocate more than 12 bytes to bar. Thanks. ![]() |
Author: | Mazer [ Thu Jun 29, 2006 9:02 am ] | ||
Post subject: | |||
If you dereference the character arrays, you will be left with two characters (the first character from each array).
So 'H' == 'H', even though "Hello" != "Hippo". |
Author: | Cervantes [ Thu Jun 29, 2006 12:03 pm ] |
Post subject: | |
Of course! I just realized that as I walked in a few minutes ago. I think I said this yesterday, but "hurray for sudden flashes of realization!" Thanks, Mazer. ![]() |
Author: | Mazer [ Thu Jun 29, 2006 12:06 pm ] |
Post subject: | |
Happy to be of service. Actually, I was honestly just happy to use "Hippo" in a post. ![]() |