zoukankan      html  css  js  c++  java
  • C++之基础

    新C++标准库的名字都放在std名字空间里边。

    int carrots(声明语句)(此时声明就是定义)(声明可以申明使用其他位置定义的变量)

        --使用足够的空间来存储一个整数;

        --以后程序中用名字carrots 来标识存储在该内存单元的一个值

    C++不允许将函数定义在函数里。

    wchar_t 更长的字节,用wcout,或者wcin

    char_t = L'A'(注:单引号)

    string类---><string>库中

    union -->公用体(同时只能存储一种)

    enum -->枚举

    C中分配地址malloc();C++中分配地址new()

    int *p = new int ---->为p分配一个地址(要与释放内存delete配对使用)(注:释放内存,释放p指向的内存,但不能删除指针p本身)

    使用new动态创建数组  int *p = new int[10] ,释放是用delete []p

    递归:

      通常的方法将递归调用放在if语句中

    void recurs()

    {

      statements1

      if (test)  --->test最终为空(先进后出)

        recurs()

      statements2

    }

    *p++;*++p;++*p;(*p)++区别:

    *p++: 先求出*p的值,然后p地址在偏移

    *++p:地址先偏移,再求值

    ++*p:前加加操作

    (*p)++:后加加操作

    例如:int a[5] = [10,20,30,40,50];int *p = a;

    (*p)++        值: 10           |  (*p)++    值:10

      ∨             |      ∨

    (*p)++     值: 11     |  *P++   值:11

      ∨             |      ∨

    *p         值: 12      |  *p    值:20

    函数内块的变量,块外不能用

    函数禁止将const指针(实参)赋给非const指针(形参) ::--->函数尽可能用const 申明形参

    内联函数(以代码增加为代价,换取时间的节约):

        inline 是C++新增特性。C语言中#define SQUARE(X)   X*X(注意这并不是通过值传,而是通过文本替换来实现的)内联按值传递

        c++ * c++ --->输出c*c c值加2  ++c *++c  --->(c+2) *(c+2)

        内联函数在编译时,会将此内联函数代码直接编译到调用函数处,减少函数调用的跳转、数据压栈等操作(一般只用于只有一两句话,调用频率高的函数)

    定义方式:(类中)

      class obj{

         int i,j;

        public:

         int add(){return i+j;} 1)----> 在类内部定义了函数体的函数

         inline int dec() {return i-j;} ---> 

         int GetNum();------->在外部去定义函数体

      };

    inline int obj::GetNum(){}

      注:一般类会把数据成员定义成私有的或者保护的,对数据进行读写定义成内联,会有好的效率

      

  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    微信小程序TodoList
    C语言88案例-找出数列中的最大值和最小值
    C语言88案例-使用指针的指针输出字符串
  • 原文地址:https://www.cnblogs.com/holens/p/4222854.html
Copyright © 2011-2022 走看看