r/programming • • May 10 '18

Java: Executing code in comments?!

http://programming.guide/java/executing-code-in-comments.html
260 Upvotes

84 comments sorted by

View all comments

3

u/sleepsort May 10 '18

Quick question. Would this work in C/C++? If I recall correctly, the CPP (C preprocessor) strips the comments from the file/code being executed.

5

u/scorcher24 May 10 '18

2

u/sleepsort May 10 '18

Thanks! Was going to test this out as soon as I got home but that adds a lot of explanation!

5

u/Drisku11 May 11 '18

You can do the opposite with C/C++ (pre-C++17) though: surprise coworkers by turning non-comment lines into comments with trigraphs.