This also depends on what variety of C you're using. Stroustrup made C++ as compatible as he could, and no more compatible, with the 1989 ANSI and 1990 ISO standards, and the 1995 version changed nothing. The C committee went in a somewhat different direction with the 1999 standard, and the C++ committee has changed the next C++ standard (probably out next year or so) to conform with some of the changes.
Stroustrup lists incompatibilities with C90/C95 in Appendix B.2 of "The C++ Programming Language", Special Edition (which is 3rd edition with some added material):
'a'
is an int
in C, a char
in C++.
The sizeof an enum is int
in C, not necessarily in C++.
C++ has //
comments to end of line, C doesn't (although it's a common extension).
In C++, a struct foo {
definition puts foo
into the global namespace, while in C it would have to be referred to as struct foo
. This allows a struct
definition to shadow a name in an outer scope, and has a few other consequences. Also, C allows larger scope for struct
definitions, and allows them in return type and argument type declarations.
C++ is fussier about types in general. It won't allow an integer to be assigned to an enum
, and void *
objects cannot be assigned to other pointer types without a cast. In C, it's possible to provide an overlarge initializer (char name[5] = "David"
where C will discard the trailing null character).
C89 allowed implicit int
in many contexts, and C++ doesn't. This means that all functions must be declared in C++, while in C89 it was often possible to get by with assuming int
for everything applicable in the function declaration.
In C, it's possible to jump from outside a block to inside using a labeled statement. In C++, this isn't allowed if it skips an initialization.
C is more liberal in external linkage. In C, a global const
variable is implicitly extern
, and that's not true in C++. C allows a global data object to be declared several times without an extern
, but that's not true in C++.
Many C++ keywords are not keywords in C, or are #define
d in standard C headers.
There are also some older features of C that aren't considered good style any more. In C, you can declare a function with the argument definitions after the list of arguments. In C, a declaration like int foo()
means that foo()
can take any number of any type of arguments, while in C++ it's equivalent to int foo(void)
.
That seems to cover everything from Stroustrup.