Does C++ contain the entire C language? [duplicate]

I have read in tutorials that C++ contains the entire C programming language.

However I have also read, in places like this that

If you learn C++ you will eventually learn most of C with some differences between the languages that you will learn over time.

So my question is only this:

If I know C++ very well, will I eventually learn the "real" C language (without any "differences") because the full C90 language is included in C++11?


No, C++ is not a superset of the C language. While C++ contains a large part of C, there are subtle difference that can bite you badly where you least expect them. Here are some examples:

  • C has the concept of tentative definitions which doesn't exist in C++.
  • C does not require explicit conversion on assignment of void pointers to variables of concrete type.
  • C has different rules regarding const propagation.
  • C has something called the “implicit int rule,” which, although abolished with C99, appears some times and needs to be considered.
  • The C preprocessor has some features the C++ preprocessor does not have.
  • The C language has two styles of function definition, K&R-style and Stroustrup-style. C++ only has Stroustrup-style.
  • The lexing rules for C and C++ are different with neither being a subset of the other
  • C and C++ have different sets of reserved words. This can cause weird errors because an identifier is not allowed in the other language.
  • While C++ took almost all features from ANSI C (C89), many features were added to C in subsequent standard revisions that are not available in C++.
  • C++ has a different syntax, even for some parts that aren't new. For example, a ? b : c = d is a syntax error in C but parsed as a ? b : (c = d) in C++.
  • C guarantees that &*E is exactly identical to E, even if E is a null pointer. C++ has no such guarantee.
  • In C, a string literal initializing an array of characters can initialize an array that is at least as long as the string without the trailing \0 byte. (i.e. char foo[3] = "bar" is legal). In C++, the array has to be at least as long as the string including the trailing \0 byte.
  • In C, a character literal like 'A' has type int. In C++, it has type char.
  • C has a special rule to make type punning through unions to be legal. C++ lacks this language, making code such as

    union intfloat {
        int i;
        float f;
    } fi;
    
    fi.f = 1.0;
    printf("%d\n", fi.i);
    

    undefined behaviour.


If I know C++ very well, will I eventually learn the "real" C language (without any "differences")

If you learn C++ properly, you will probably not need to use many of the standard techniques used in C. Theoretically you could program almost anything C in C++, with exceptions that have already been introduced. However, in reality, you wouldn't - or shouldn't. This is because C++ is a different language that provides a very different set of tools when used optimally.

Aside from the very basic elements like general syntax and fundamental types, these are two separately evolving languages, and they should be approached (learned, programmed) as such.


In broad terms, the C++ language is essentially C with a whole bunch of object oriented stuff added. Nearly all the code you could write in C will also compile and run just fine in C++.

However, there are a few corners of the languages where there are differences. The number of these have been slowly growing over time, but the languages aren't changing rapidly enough for that to be a significant problem.

If you only learn C++, then yes, you will eventually learn almost all aspects of the C language too. If you become expert in C++, then you will be able to identify and understand the places where small differences between the similar parts of C and C++ exist.


I am not sure what "differences" might exist...

For example like this one:

In C:
void foo() means "a function foo taking an unspecified number of arguments of unspecified type"
[...]
In C++:
void foo() means "a function foo taking no arguments"