 <p>Assuming you're on a linux/unix machine with the GNU toolchain you could check this easily by:</p> <p>Copying the above code into test.c:</p> <pre><code>$ echo "int temp = temp +1; int main() { return temp; }" &gt; test.c </code></pre> <p>Testing to see if it's valid C (it's not):</p> <pre><code>$ gcc test.c test.c:2: error: initializer element is not constant </code></pre> <p>Testing to see if it's valid in C++ (it is!):</p> <pre><code>$ g++ test.c </code></pre> <p>Checking the return code:</p> <pre><code>$ ./a.out &amp;&amp; echo "success: return code $?" || echo "failure: return code $?" failure: return code 1 </code></pre>