• 01HelloWorld20220615


    01-课程安排

    02-第一个c++程序

    1,c++的7行代码框架

    2,cout <<""<< endl;         //打印

    3,cout输出,cin输入,<<代表输入输出标识符,endl代表换行。

    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << "Hello World" << endl;
    
    	cout << "Hello C++" << endl;
    
    	system("pause");
    
    	return 0;
    }
    

    03-程序的注释:单行注释和多行注释

    04-变量的使用,变量的意义。-- 存在内存中。

    05-常量与变量的区别,常量的使用 

    常量的定义方式:
    1,#define 宏常量

    #define Day 7;


    2,const修饰的变量

    const int month = 12;

    06-c++中常用的关键字

    07-标识符命名规则

    1,不可以是关键字

    2,字母,数字和下划线

    3,第一个字母是字母或下划线

    4,区分大小写

    08-数据类型-整型

    1,数据类型存在的意义——给变量分配合适的存储空间

    short:2个字节

    int:4

    long:4

    long long:8

        short num1 = 32767;  //2的15次方
        int num2 = 10; //2的31次方
        long num3 = 10; //2的31次方
        long long num4 = 10; //2的63次方
    
        cout  << num1 << endl;
        cout << "num1=" << num1<< endl;
        cout << "num2 = " << num2 << endl;
        cout << "num3 = " << num3 << endl;
        cout << "num4 = " << num4 << endl;    

    09-数据类型--sizeof关键字

    作用:计算变量的数据类型的内存占用空间

    short num1 = 32767;  //2的15次方
        int num2 = 100; //2的31次方
        long num3 = 10; //2的31次方
        long long num4 = 10; //2的63次方
    
    
        cout << "sizeof占用内存空间" << sizeof(num1)<< endl;
        cout << "sizeof占用内存空间 = " << sizeof(num2) << endl;
        cout << "sizeof占用内存空间 = " << sizeof(num3) << endl;
        cout << "sizeof占用内存空间 = " << sizeof(num4) << endl;

    10-数据类型——实型(浮点型)

    1,单精度:float   ,4个字节,变量值后面会加一个f,否则会认为是double类型

    2,双精度:double,8个字节,

    float f1 = 3.1415926f;
        double d2 = 3.14;
    
        cout << "f1=" << f1 << endl;
        cout << "sizeof占用内存空间f1 = " << sizeof(f1) << endl;
        cout << "d2 = " << d2 << endl;
        cout << "sizeof占用内存空间d2 = " << sizeof(d2) << endl;

    11-数据类型——字符型

    1,c和c++中占一个字节

    2,字符型变量不是放在内存中,而是将对应的ASCII编码放入到存储单元

    两个常见ASCII值(用int强转可以看见)

    a-97

    A-65

    12-数据类型——转义字符

    常用

    换行符:\n

    水平制表符:\t   --它是包括前面字符一起占用8个字符,作用是整齐的输出数据

    13-字符串型

    1,C风格字符串: char变量名[],“”

    2,C++ 字符串 string

    14-数据类型——布尔类型bool

    1,占1个字节大小

    2,本质上1代表真,0代表假

    15-数据类型——数据输入cin

  • 相关阅读:
    Linux下安装破解JIRA 6.3.6 并连接MYSQL5
    centos7 系统安装问题汇总
    CentOS7安装iptables防火墙
    Vue全家桶实战 从零独立开发企业级电商系统
    小米笔记本pro充电10秒断开
    mac电脑的使用
    autojs解决方案
    auto.js连接vscode
    小米6手机刷机亲测详解
    #002前端基础-JS-浏览器中堆栈内存的底层处理
  • 原文地址:https://www.cnblogs.com/faithfeng/p/16377473.html
Copyright © 2020-2023  润新知