指针的基本知识

C++版

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{

    char ch[6] = "hello";
    char* pch = ch;
    // char数组可以用指针来修改
    pch[0] = 'x';
    char *p = "hello";
    // "hello"本身已经是一个字符串常量,不是数组所以不能修改
    p[0] = 'H';
    int a[3] = {1,2,3};
    int *b = a;
    // int数组可以用指针来修改
    b[0] = 4;
    for(int i = 0; i < 3; i++){
        cout<<a[i]<<endl;
    }
    cout<<pch<<endl;
    return 0;
}

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2021-09-02
  • 2021-11-30
  • 2021-12-03
  • 2022-01-04
  • 2022-12-23
  • 2021-05-23
猜你喜欢
  • 2021-10-15
  • 2021-07-15
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
相关资源
相似解决方案