Search code examples
c++comments

How to prevent /* from creating a comment block?


I'm trying to print out the following:

cout << *pointer1/*pointer2 << endl;

However, because /* opens a comment block, everything past /* is treated as a comment. The solution I've come up so far is this:

int tempPointer = *pointer;
cout << *pointer1/tempPointer << endl;

This works but isn't very elegant.

Is there a way to prevent /* from creating a comment block in this instance?


Solution

  • Just add a space or put the pointer dereference in brackets. (This also improves readability.)

    cout << *pointer1 / *pointer2 << endl;
    

    or

    cout << *pointer1/(*pointer2) << endl;