zoukankan      html  css  js  c++  java
  • C++ Primer 读书笔记 第五章

    这一章的内容和C语言基础知识大同小异。

    1. i++ 与 ++i 的效率问题

        i++的话,需要保存原来的值,然后增加 i,之后返回 i 原来的值;++i 直接增加 i,然后返回当前的 i 值,所以少做一步工作。

    2. Setting the pointer to 0 after the object it refers to has been deleted makes it clear that the pointer points to no object.

        It is legal to delete a pointer whose value is zero; doing so has no effect.

    #include <iostream>
    #include <cstdlib>
    using namespace std;
    
    void print(int a[])
    {
        cout << sizeof(a)/sizeof(*a) << endl;
    }
    
    int main()
    {
        int a[9] = {0};
        cout << sizeof(a)/sizeof(*a) << endl;
        print(a);
        
        int *arr = new int[9];
        free(arr);
        arr = NULL;
        delete [] arr;
        
        int *b = (int *)malloc(sizeof(int));
        delete b;
        b = NULL;
        free(b);
        return 0;
    }
  • 相关阅读:
    JAVA-JDBC
    如何优雅地拼SQL的in子句
    Groovy 语言尝鲜
    小而美的CNC机器
    GCode软件和资料
    基于PC的运动控制
    CAD/CAM软件
    工控硬件
    数控系统
    Visual Studio 2019 Community 版离线注册
  • 原文地址:https://www.cnblogs.com/null00/p/3088080.html
Copyright © 2011-2022 走看看