C++与C的区别终于说清楚了!

int slice();int main(){...slice(20, 50);...}int slice(int a, int b){...}
char ch = 'A';
int x = 'ABCD'; /*对于int是4字节的系统,该语句出现在C程序中没问题,但是出现在C++程序中会出错 */
int x = 'ABCD';char c = 'ABCD';printf("%d %d %c %c\n", x, 'ABCD', c, 'ABCD');
在我们的系统中,得到的输出如下:
1094861636 1094861636 D D
const double PI = 3.14159;
static const double PI = 3.14159;
const int ARSIZE = 100;double loons[ARSIZE]; /* 在C++中,与double loons[100];相同 */
const double RATE = 0.06; // C++和C都可以const double STEP = 24.5; // C++和C都可以const double LEVEL = RATE * STEP; // C++可以,C不可以
struct duo{ int a; int b;};struct duo m; /* C和C++都可以 */duo n; /* C不可以,C++可以*/#includefloat duo = 100.3;int main(void){struct duo { int a; int b;};struct duo y = { 2, 4};printf ("%f\n", duo); /* 在C中没问题,但是在C++不行 */return 0;}
struct box{struct point {int x; int y; } upperleft;struct point lowerright;};
struct box ad; /* C和 C++都可以 */struct point dot; /* C可以,C++不行 */box::point dot; /* C不行,C++可以 */
enum sample {sage, thyme, salt, pepper};enum sample season;season = sage; /* C和C++都可以 */season = 2; /* 在C中会发出警告,在C++中是一个错误 */season = (enum sample) 3; /* C和C++都可以*/season++; /* C可以,在C++中是一个错误 */
enum sample {sage, thyme, salt, pepper};sample season; /* C++可以,在C中不可以 */
int ar[5] = {4, 5, 6,7, 8};int * pi;void * pv;pv = ar; /* C和C++都可以 */pi = pv; /* C可以,C++不可以 */pi = (int * ) pv; /* C和C++都可以 */
《C Primer Plus(第6版)中文版》在之前版本的基础之上进行了全新升级,它涵盖了C语言*新的进展以及C11标准的详细内容。本书还提供了大量深度与广度齐备的教学技术和工具,来提高你的学习。
《C++ Primer Plus(第6版)中文版》针对C++初学者,从C语言基础知识开始介绍,然后在此基础上详细阐述C++新增的特性,因此不要求读者有C语言方面的背景知识。《C++PrimerPlus(第6版)中文版》可作为高等院校教授C++课程的教材,也可供初学者自学C++时使用。
评论
