Just studying the C style of Jon Bentley's Programming Pearls and was wondering if someone could please explain to me the following two pieces of C syntax:
A for
with no init condition (see line 2 in wordncmp in the file above):
for ( ; *p == *q; p++, q++)
and the semantic difference between
char *word[800000];
and
char word[800000];
since I thought arrays were just pointers to, in this case, word[0]
.
Answer choice explanation: Ok, as the rest of the community, I was torn between accepting dmckee or CAbbott answer. They both have important pieces of knowledge that I appreciate. I've accepted CAbbott answer because it was simpler, but gave an upvote to dmckee. As fair as I could go without accepting two answers. Thanks.
It's been a while, but here should be the differences:
for ( ; *p == *q; p++, q++)
This is simply that the developer doesnt want to do any initialization prior to the for loop. In this case the developer simply wants to iterate through the pointers.
char *word[800000];
and
char word[800000];
The first declares an array of 800000 char*, the second is an array of 800000 chars
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With