In problem set 5, there are these two lines of code.

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

Both of theses operations seem to define a 'pointer-to-a-char' variable. Could someone please identify the difference between these two assignment operations? Specifically char* <name> = ... vs char *<name> = ...

Also, Is this something specific to the char data type? I don't recall seeing any thing like this for int, for example.

Thanks a lot.


In this case I do not know what the confusion is, both are pointers to a char, you just have to look at the right part of the statement, maybe you have some doubt with the dereference operator, which is written like the declaration of a pointer, but when p is a pointer the statement *p (operator dereference) is the value of any variable, an integer value for example, in the case of strings the thing can be significantly complicated, it is worth a careful study of each case and we must to be careful, the treatment of strings in c can be a pain in the neck.

  • Thanks for the response. Ok, so to define a pointer to a char called 'dictionary' for example, you can say either char* dictionary = ... or char *dictionary = ... They are the same. – Peter Szujewski Nov 5 '17 at 18:40
  • It is the same, but the most accepted convention is the first case – MARS Nov 5 '17 at 18:52
  • Great thanks a lot for the help – Peter Szujewski Nov 5 '17 at 18:54

You must log in to answer this question.

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