cpp指针操作

作者: 李药师_hablee | 来源:发表于2019-03-07 16:13 被阅读0次
cpp指针.png cpp指针2.png cpp指针3.png

cpp指针3的代码

//指针自增自减运算

#include<iostream>
using namespace std;

int main()
{
    int a[3] = { 10,20,30 };
    int *p;
    p = a;
    cout << *p++ << endl;//取值,然后++
    cout << *p << endl;//取下一个值
    
    system("pause");
    return 0;
}

输出

输出1.PNG
//指针自增自减运算

#include<iostream>
using namespace std;

int main()
{
    int a[3] = { 10,20,30 };
    int *p;
    p = a;
    cout << (*p)++ << endl;//取值,然后++
    cout << *p << endl;//取++之後的值
    
    system("pause");
    return 0;
}

输出

输出2.PNG cpp指针4.png

cpp指针4的代码

//指针相减运算

#include<iostream>

using namespace std;

int main()
{
    char *p, *q;
    p = new char[100];
    gets_s(p,100);//获得输入的数据
    q = p;
    //输出
    while (*p!='\0')
    {
        cout << *p++;
    }

    cout << endl;
    cout << "length is " << p - q << endl;//计算字符串长度

    system("pause");
    return 0;
}
输出.PNG

以上代码在 visual studio 2017 community版本中编译运行

相关文章

  • cpp指针操作

    cpp指针3的代码 输出 输出 cpp指针4的代码 以上代码在 visual studio 2017 commun...

  • Cpp:指针

    2015/11/13 16:16更新: 为什么得到的喜欢数少于关注的人数呢?我分析了一下原因,难道是因为“喜欢”按...

  • c经典多级指针练习,写一个简单的集合

    1:经典的指针习题,求打印结果 结果执行是 首先画一下变量在内存中的位置 ++cpp,后cpp三级指针指向cp二级...

  • cpp智能指针

    搜了下智能指针的博客,发现很乱,c++ Primer上也一大堆废话,有时看的不知所云。 最后在博客园上找到一个总结...

  • LeetCode—— 移动零

    题目描述 一、CPP 1. 双指针法: 解题思路:使用两个指针,指针 i 负责遍历数组,指针 j 负责其后的元素均...

  • CPP内容捡拾

    指针的指针 指针的指针用于形参,可以实现对传入参数本体的修改,且建立与原值的关联。 在cpp中,可以使用*&替代*...

  • Rust for cpp devs - 智能指针

    与 cpp 类似,Rust 也有智能指针。Rust 中的智能指针与引用最大的不同是,智能指针 own 内存,而引用...

  • c++快速入门6:指针与引用

    了解数据存储 address.cpp 用指针获取数值 指针存储其他变量的内存地址的变量。指针变量的声明方式与其他变...

  • cpp数组(二):认识指针

    作者邮箱:z_zhanghaobo@163.comgithub相关: https://github.com/Hao...

  • cpp数组(三):数组指针

    作者邮箱:z_zhanghaobo@163.comgithub相关: https://github.com/Hao...

网友评论

    本文标题:cpp指针操作

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