zoukankan      html  css  js  c++  java
  • c++学习(1)

    c++学习(1)

    1.const C VS C++

    c语言中const是一个只读变量(ReadOnly Varible),在c++const只是代表常量(Constant)。

    例:

    const int n=10

    int arry[10]//OK in c++ error in c

    2.指针的两个属性:

    (1).指针本身;

    (2).指针所指向的数据;

    3.常量指针和指针常量:

    (1).常量指针Point to constant or constant point):

    概念:指向常量的指针;

    定义:const int* p;

    例:

    const int * p1;

    const int x=1;

    p1=&x;//正确

    *p1=10;//错误

    此处常量指的是解引用为常量;

    (2).指针常量point constant

    概念:不可变的指针指向一个可变的值;

    定义:int* const p;

    例:

    const int x=1

    int* const p1=&x;//超级重要的一步,一定要写上p1要指向谁

    *p1 = x//or y,也可以不写,不写的话代表p1指向的那个变量的值;

    p1=&y//是错误的,因为指针常量中指针是不可以变的

    #数组名就是一个指针常量!!

  • 相关阅读:
    spring的原理
    角色&权限
    Redis在springboot项目的使用
    项目接口的设计思想
    springboot项目注册接口
    Redis
    cookie&session
    python enumerate()
    原来,一直没有完全理解range()函数
    python zip()和zip(*)方法
  • 原文地址:https://www.cnblogs.com/czwangzheng/p/4603383.html
Copyright © 2011-2022 走看看