Search code examples
c++ccomments

How to comment out a few lines, with comments inside


I have a program like this:

int main(){ 
          
    char c;
    int i; /* counter */
    double d;
 
    return 0;
}

If I want to comment out the lines with char, int and double, and just have return 0; uncommented, can I do it? the comment that's already there stops the comment. Is there an easy/fast way to comment that out?


Solution

  • int main(){ 
    #if 0
        char c;
        int i; /* counter */
        double d;
    #endif
        return 0;
    }
    

    Not strictly a comment, but the effect is what you want and it's easy to revert.

    This also scales well to larger code blocks, especially if you have an editor that can match the start and end of the #if..#endif.