c++csyntax

Make the meaning of /* for dereference and dividing not for commenting by adding some special character


I have a code like this:

int quotient = 100/*ptr; 

where ptr is a pointer to integer.
But it's taking /* as the comment.

How can I make the meaning of divide by a pointer-dereferenced value? What extra special character I have to put to have this meaning?


Solution

  • This happens because language tried to reuse the tokens. (* in this case)

    Solution is to put a space between / and * to beat maximal munch.

    int quotient = 100 / *ptr;
    

    Another way is to add a parenthesis or use another local variable:

    int quotient = 100/(*ptr);