美文网首页
指针和 const 关键字

指针和 const 关键字

作者: LunaElf | 来源:发表于2019-03-12 18:18 被阅读0次

今天看 OOP in C 的时候碰到了这种声明 Shape const * const me。上网查了一下资料,做个总结。

int *p1; // p1 is a pointer to int
const int *p21; // p21 is a pointer to const int
int const *p22; // p22 is a pointer to const int
int *const p3; // p3 is a constant pointer to int
const int *const p41; // p41 is a constant pointer to const int
int const *const p42; // p42 is a constant pointer to const int

阅读诀窍是从右往左读,直到碰到第一个 *。如果 * 右边有 const,那么这个指针是常量指针。左边的 constint 可以互换。

参考资料:

相关文章

  • 指针和 const 关键字

    今天看 OOP in C 的时候碰到了这种声明 Shape const * const me。上网查了一下资料,做...

  • 常量指针和指针常量

    const关键字用来定义常量,如果一个变量被const修饰,那么他的值就不能被改变。 常量指针 (常量指针是指针指...

  • C++ const 关键字

    本文是对const关键字的一个简单总结,测试环境IDE的是Xcode13.2.1 一、const及常量指针、指针常...

  • 5.const与指针

    1.const修饰指针-常量指针 2.const修饰常量-指针常量 3.const修饰指针和常量 代码如下

  • day10

    const关键字如果const写在指针类型的左边, 那么意味着指向的内存空间中的值不能改变, 但是指针的指向可以改...

  • cpp一些常见问题

    本篇主要涉及cpp的常见关键字,强制类型转换,和智能指针的粗浅用法。 cpp常见关键字 1. const 修饰变量...

  • c语言之const和指针

    const和指针 区别方法:如果const位于*的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量...

  • const修饰指针

    今天我看了一下const修饰指针的几种情况,总结一下: 总结一句话就是,const关键字在*之前,修饰的指针所指的...

  • c++ 指针和引用的区别

    1. 指针有const,引用没有const 1)为了限制指针更改指向,引入了const指针(int* const ...

  • C语言-const指针

    const 指针 在普通指针类型前面,加上const修饰 例如: const 指针:区别 加不加const,有什么...

网友评论

      本文标题:指针和 const 关键字

      本文链接:https://www.haomeiwen.com/subject/ckonpqtx.html