1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <fstream> #include <string> #include <<a href="https://www.bokeyuan.net/topic/windows">Windows</a>.h> using namespace std; // <a href="https://www.bokeyuan.net/topic/zhizhen">指针</a><a href="https://www.bokeyuan.net/topic/shu">数</a>组和数组指针真的没有弄明白 int main() { int ppp[3][4] = { {1,2,3,8} ,{4,5,6,8} ,{7,8,9,8} }; int *p = &ppp[3][4]; // 一维数组的指针 int nuo[3] = {7,55,9}; int *pp = nuo; int *pp1 = &nuo[0]; cout <<pp<<pp1 << endl; // 他们都是地址 cout << *pp<<*pp1<< endl; // 他们的值 /*for (int i = 0; i < 7; i++) // 都能够 自增 { cout <<“pp =”<< *pp++ << endl; cout <<“pp1 =” <<*pp1++ << endl; }*/ // 二位数组的指针 1数组指针和2指针数组 int num[3][4] = { {55,78,95,11},{35,64,15,85},{64,325,48,77} }; //1指针数组 : 是数组里面存放着指针!~可以保存某一个地址!~ int *pZhiZhenSuZu[2]; pZhiZhenSuZu[0] =& num[0][0]; // 2.数组指针 int (*pSuZuZhiZhen)[4]; // 指向了四个成员的数组指针 访问<a href="https://www.bokeyuan.net/topic/yuansu">元素</a>的两种方式1:数组指针下标法(*p)[j] 2:数组指针访问法*((*p)+j) pSuZuZhiZhen = &ppp[0]; for ( int i = 0; i < 3; i++) { for ( int j = 0; j < 4; j++) { cout <<“数组指针1:”<< (*pSuZuZhiZhen)[j]<< endl; } pSuZuZhiZhen++; } pSuZuZhiZhen = &ppp[0]; for ( int i = 0; i < 3; i++) { for ( int j = 0; j < 4; j++) { cout << “数组指针2:” << *((*pSuZuZhiZhen)+j) << endl; } pSuZuZhiZhen++; } // 普通指针访问二维数组 int *PuTong = ppp[0]; // 因为后面属于地址所以不需要引用 int *puTong = &ppp[0][0]; // 两个就是值了所以需要引用 // 因为数组是连续的所以,就能够直接访问3*4 [3][4]次数 system(“pause”); return 0; } |
指针记
请登录之后再进行评论
登录
你好:已帮你在电脑端改为“代码模式”效果更好,如下截图(博科园在电脑端是支持多种代码语言选择的)