C++
C++ 是一种静态类型的、编译式的、通用的、大小写敏感的、不规则的编程语言,支持过程化编程、面向对象编程和泛型编程;C++ 通常用于编写设备驱动程序和其他要求实时性的直接操作硬件的软件
C++ 是由 Bjarne Stroustrup 于 1979 年在新泽西州美利山贝尔实验室开始设计开发的;注意:使用静态类型的编程语言是在编译时执行类型检查,而不是在运行时执行类型检查。
#include<iostream>
#include<limits>
using namespace std;
int main(){
cout<<"Hello World"<<"\n";
cout<<5+2*3<<endl;
cout<<"bool min:"<<(numeric_limits<bool>::min)()<<endl;
cout<<"bool max:"<<(numeric_limits<bool>::max)()<<endl;
cout<<"char min:"<<(numeric_limits<char>::min)()<<endl;
cout<<"char max:"<<(numeric_limits<char>::max)()<<endl;
cout<<"int min:"<<(numeric_limits<int>::min)()<<endl;
cout<<"int max:"<<(numeric_limits<int>::max)()<<endl;
cout<<"float min:"<<(numeric_limits<float>::min)()<<endl;
cout<<"float max:"<<(numeric_limits<float>::max)()<<endl;
cout<<"double min:"<<(numeric_limits<double>::min)()<<endl;
cout<<"double max:"<<(numeric_limits<double>::max)()<<endl;
}
对象 - 对象具有状态和行为。例如:一只狗的状态 - 颜色、名称、品种,行为 - 摇动、叫唤、吃。对象是类的实例
C++ 标识符是用来标识变量、函数、类、模块,或任何其他用户自定义项目的名称;一个标识符以字母 A-Z 或 a-z 或下划线 _ 开始,后跟零个或多个字母、下划线和数字(0-9)
C++ 中的保留字。这些保留字不能作为常量名、变量名或其他标识符名称:asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while
C++ 注释一般有两种://一般用于单行注释;/* 注释内容 */ 一般用于多行注释
数据类型:基本内置数据类型;
基本类型:
布尔型:bool
字符型:char //1个字节 -128 到 127 unsigned char 0 到 255
整型:int //4个字节 -2147483648 到 2147483647
浮点型:float //4 个字节 精度型占4个字节(32位)内存空间
双浮点型:double //8个字节 双精度型占8 个字节(64位)内存空间
无类型:void
宽字符型:wchar_t
一些基本类型可以使用一个或多个类型修饰符进行修饰:signed unsigned short long
typedef 为一个已有的类型取一个新的名字:typedef int feet;
枚举类型(enumeration)是C++中的一种派生数据类型,它是由用户定义的若干枚举常量的集合
enum color { red, green, blue } c; c = blue;
变量的作用域:局部变量、全局变量、形式参数
在函数或一个代码块内部声明的变量,称为局部变量。在所有函数外部定义的变量(通常是在程序的头部),称为全局变量
局部变量可以和全局变量同名,在函数内,局部变量的值会覆盖全局变量的值
常量是固定值,在程序执行期间不会改变。这些固定的值,又叫做字面量;0x 或 0X 表示十六进制,0 表示八进制
整数常量也可以带一个后缀,后缀是 U 和 L 的组合,U 表示无符号整数(unsigned),L 表示长整数(long)。后缀可以是大写,也可以是小写,U 和 L 的顺序任意。
布尔常量共有两个:true 值代表真、false 值代表假
运算符表达式
流程控制语句
数组