指针 & 常量
常量指针和指针常量
- 指针常量 :指针(地址)是常量,内容是变量 const char * oc = s
- 常量指针 :内容是常量,地址可以改变 char * const cp = s
- const char * cosnt cpc //指针的值和地址都不能改变
不允许将一个常量指针的地址赋给一个不加限制的变量指针
指针好难啊 …….
行指针和列指针的应用,列指针就是我们普通理解上的指针的应用,行指针就是一个很奇怪的东西,列指针 ++ 就是下一个地址, 行指针 ++ 就是指针地址指向下一行.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int a[3][4] = {0};
int start = 1;
int main () {
ios_base :: sync_with_stdio(false);
for (int i = 0;i < 3; ++ i) {
for (int j = 0;j < 4; ++ j) {
a[i][j] = start;
start += 2;
}
}
int (*point)[4] = a;
int *p = a[0];
for (int i = 0;i < 3; ++ i) {
for (int j = 0;j < 4; ++ j) {
cout << *p << ' ';
p ++;
}
cout << endl;
}
for (int i = 0;i < 3; ++ i) {
for (int j = 0;j < 4; ++ j) {
cout << *(*(point + i) + j) << ' ';
}
// point ++;
cout << endl;
}
return 0;
}