本文介绍了帮助指针! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I understood most of the code but I am unclear on what the line ptr=-2 does to the overall code
    I mean does it change address of ptr or something ?

#include <iostream>

using namespace std;

void processptr(int *ptr)
{
    for(int i=4;i>2;i--)
    {
        (*ptr)*=i;
        ptr-=2;
    }
}

int main()
{
    int numbers[]={2,4,8,10};
    int *ptr=numbers+3;
    cout<<*ptr;
    cout<<'\n';
    processptr(ptr);
    cout<<'\n';
    for(int i=0;i<4;i++)
    {
    cout<<numbers[i]<<"@";
    cout<<"\n"<<i;
    }

    return 0;
}





我的尝试:



我尝试运行代码并查看输出但我仍然无法完全理解代码



What I have tried:

I tried Running the code and seeing the output but I still can't fully understand the code

推荐答案



这篇关于帮助指针! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:38