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;
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.
Sign up to join this communityAssuming 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;
}