请问C ++包含了整个C语言? [英] Does C++ contain the entire C language?
问题描述
我已阅读在C ++中包含了整个C语言教程。
I have read in tutorials that C++ contains the entire C programming language.
不过,我也看到了,在地方这样的
However I have also read, in places like this that
如果你学习C ++,你会最终学会大多数C的与你将学习一段时间语言之间的一些差异。
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:
如果我知道C ++非常好,我将最终学会真正的C语言(没有任何分歧),因为完整的C90语言包括在C ++ 11?
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?
推荐答案
没有,C ++不是C语言的超集。虽然C ++含有C的很大一部分,有可能咬你不好,你至少期望他们细微的差别。下面是一些例子:
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不要求在
无效
指向具体类型的变量赋值显式转换。 - C有关于
常量不同的规则
传播。 - C有一种叫做隐性
INT
规则,其中,虽然与C99取消了,显得有些时候,需要考虑的。 - 的C preprocessor有一些功能的C ++ preprocessor没有。
- C语言有两种风格的函数定义,K&放大器; R-风格和Stroustrup的风格。 C ++只有Stroustrup的风格。
- C和C的词法规则++与既不是另一个 的一个子集不同
- C和C ++有不同的套保留字。这可能会导致奇怪的错误,因为一个标识符未在其他语言允许的。
- 当C ++几乎花了所有的功能从ANSI C(C89),很多功能都在随后的修订标准所不具备的C ++加入到C
- C ++有不同的语法,甚至有些部分是不是新的。例如,
A? B:C = D
在C语法错误,但分析为A? B:(C = D)
在C ++ - ç保证
&放大器; * E
是完全相同电子
,即使Ë
是一个空指针。 C ++有没有这样的保证。 - 在C,一个字符串初始化字符数组可以初始化数组至少是只要没有尾随
\\ 0
字节字符串。 (即字符富[3] =栏
是合法的)。在C ++中,数组至少只要是为包括结尾的字符串\\ 0
字节。 - 在C,文字像
字符'A'
的类型INT
。在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 asa ? b : (c = d)
in C++. - C guarantees that
&*E
is exactly identical toE
, even ifE
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 typeint
. In C++, it has typechar
.
这篇关于请问C ++包含了整个C语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!