Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Overview:</strong></p> <p>It is almost true that C++ is a superset of C, and your professor is correct in that there is no need to learn C separately. </p> <p>C++ adds the whole object oriented aspect, generic programming aspect, as well as having less strict rules (like variables needing to be declared at the top of each function). C++ does change the definition of some terms in C such as structs, although still in a superset way.</p> <p><strong>Examples of why it is not a strict superset:</strong></p> <p><a href="http://en.wikipedia.org/wiki/C%2B%2B" rel="noreferrer">This Wikipedia article</a> has a couple good examples of such a differences:</p> <blockquote> <p>One commonly encountered difference is that C allows implicit conversion from void* to other pointer types, but C++ does not. So, the following is valid C code:</p> <pre><code>int *i = malloc(sizeof(int) * 5); </code></pre> <p>... but to make it work in both C and C++ one would need to use an explicit cast:</p> <pre><code>int *i = (int *) malloc(sizeof(int) * 5) </code></pre> <p>Another common portability issue is that C++ defines many new keywords, such as new and class, that may be used as identifiers (e.g. variable names) in a C program.</p> </blockquote> <p><a href="http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B" rel="noreferrer">This wikipedia article</a> has further differences as well:</p> <blockquote> <p>C++ compilers prohibit goto from crossing an initialization, as in the following C99 code:</p> </blockquote> <pre><code> void fn(void) { goto flack; int i = 1; flack: ; } </code></pre> <p><strong>What should you learn first?</strong></p> <p>You should learn C++ first, not because learning C first will hurt you, not because you will have to unlearn anything (you won't), but because there is no benefit in learning C first. You will eventually learn just about everything about C anyway because it is more or less contained in C++.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload