#include <stdio.h>
#define NUMBER 20
#define OPTION 6
void main ()
{
int optionList[NUMBER]=
{4,4,5,2,1,3,1,0,4,3,3,1,2,5,4,2,3,4,3,1};
int count[OPTION] = { 0 } ;
for (int i = 0; i <= NUMBER-1; i++)
++count[optionList[i]];
}
I don't understand ++count[optionList[i]]. Is it a loop increment for both array 'count 'and 'optionList'? How does it work?
int x = optionList[i], and then++count[x]EssentiallyoptionListhere is used as a lookup table that maps values 0...19 to 0...5i <= NUMBER-1you can usei < NUMBER. The latter is more common, so more people will recognize it and understand it immediately, as well as being less to write.++count[optionList[i]];increments values in thecountarray. Its not at all a "loop increment" --i++is a loop increment. Also aside:mainis NOTvoid-- its meant to return anintvoid main ()regardless of what non-conforming compilers may allow, there are only two valid signatures formain()They are:int main( void )andint main( int argc, char *argv[] )