c++学习(1)
2015-06-26 22:48
218 查看
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//是错误的,因为指针常量中指针是不可以变的
#数组名就是一个指针常量!!
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//是错误的,因为指针常量中指针是不可以变的
#数组名就是一个指针常量!!
相关文章推荐
- 【leetcode c++】66 Plus One
- 【leetcode c++】58 Length of Last Word
- 【leetcode c++】38 Count and Say
- More Effective C++ 条款13 以reference方式捕捉exception
- C/C++ 内置类型转换注意点
- 开始学习C++心得实例(6)
- 【leetcode c++】28 Implement strStr()
- C++中堆和栈的完全解析
- C++对象内存分布(2) - 菱形继承(non virtual)
- C++ 虚函数表解析
- More Effective C++ 条款12 了解”抛出一个exception"与“传递一个参数”或“调用一个虚函数”之间的差异
- 黑马程序员--c语言函数
- Motion sensing game (Ping Pong Game)
- 随机函数rand()[c++]
- 黑马程序员--c语言各种运算
- c++ 设计模式.pdf
- [C++]水仙花数
- 提高C++程序运行效率的10个简单方法
- c语言函数回调函数回调
- 进程、线程同步互斥学习 —— 事件