5

I am not sure if I understand what this piece of code in speller.c is trying to accomplish.

char* dictionary = (argc == 3) ? argv[1] : DICTIONARY;
29

Assuming you know how a Ternary Operator works, lets visualize the above statement as an assignment statement.

char* dictionary    =    ((argc == 3) ? argv[1] : DICTIONARY);

It simply assigns a value to the memory block at which pointer dictionary points. But exactly what value is initialized to that memory block, is decided by the ternary operator on the basis of a condition whether argc == 3. If its true, then it is initialized by argv[1] else with DICTIONARY. The if-else construct for the corresponding statement would look like this.

if (argc == 3)
{
      char* dictionary = argv[1];
}
else
{
      char* dictionary = DICTIONARY;
}
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .