下载后可任意编辑Pascal/C/C++语句对比(补充版)一、Hello world 先看三种语言的样例:Pascalbegin writeln(‘Hello world’);end.C#include int main(){ printf("Hello world!\n"); return 0;}C++#include using namespace std;int main(){cout << "Hello world!" << endl; return 0;} 从这三个程序可以看到一些最基本的东西。在 Pascal 中的 begin 和 end,在 C/C++里就是{};Pascal 主程序没有返回值,而 C/C++返回 0(好像在 C 中可以为 NULL)。在 C/C++中,main 函数以前的是头文件,样例中 C 为 stdio.h,C++除了 iostream 还有第二行的 using namespace std,这个是打开命名空间的,NOIP 不会考这个,可以不管,只要知道就行了。 此外说明 注释单行用//,段落的话 Pascal 为{},C/C++为/* */。** 常用头文件(模板)#include #include #include #include #include #include using namespace std;int main(){ … …system(“pause”);return 0;}下载后可任意编辑二、数据类型及定义 这里只列出常用的类型。1、整型PascalC/C++范围shortint--128 … 127integershort-32768 … 32767longintInt -2147483648 … 2147483647int64long long-9223372036854775808 … 9223372036854775807byte-0 … 255wordunsigned short0 … 65535longwordunsigned int0 … 4294967295qwordunsigned long long0 … 18446744073709551615 ** 当对 long long 变量赋值时,后要加 LLLong long x=6327844632743269843LL** 假如位移 x<<2LL** Linux: printf(“%lld\n”,x);** Windows: printf(“%I64d\n”,x);2、实型PascalC/C++范围realfloat2.9E-39 … 1.7E38single-1.5E-45 … 3.4E38doubledouble5.0E-324 … 1.7E3083、字符即字符串 字符在三种语言中都为 char,C 里没有字符串,只有用字符数组来代替字符串,Pascal 和 C++均为 string。Pascal 中字符串长度有限制,为 255,C++则没有。 字符串和字符在 Pascal 中均用单引号注明,在 C/C++中字符用单引号,字符串用双引号。4、布尔类型 Pascal 中为 boolean,C/C++ 为 bool。值均为 True 或 False。C/C++中除 0 外 bool 都为真。5、定义 常量的定义均为 const,只是在 C/C++中必须要注明常量的类...