Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 指向指针的指针int*p和int**pc++;_C++_Pointers - Fatal编程技术网

C++ 指向指针的指针int*p和int**pc++;

C++ 指向指针的指针int*p和int**pc++;,c++,pointers,C++,Pointers,声明int*p是否有区别;或int**p;我知道**p用于指向指针的指针,但*p也可以指定给指针,所以我的问题是它们之间有区别吗 void main() { int numDays; double sum = 0; double avg; cout << "Enter the number of days of sales"; cin >> numDays; double *Sales = new double[numDa

声明int*p是否有区别;或int**p;我知道**p用于指向指针的指针,但*p也可以指定给指针,所以我的问题是它们之间有区别吗

void main()
{

    int numDays;
    double sum = 0;
    double avg;
    cout << "Enter the number of days of sales";
    cin >> numDays;
    double *Sales = new double[numDays];
    double *p = Sales;
    for (int i = 0; i < numDays; i++)
    {
        cout << "enter how much you sold for day " << i << endl;
        cin >> *p;
        sum = sum + *p;
        p++;


    }


    avg = sum / (numDays);
    cout << "the sum is" << sum << endl;
    cout << "the avg is" << avg << endl;

    delete[]Sales;

或者你可以吗?

它们是不同的类型。一个
int
上的一级间接寻址,而不是两级间接寻址

我知道**p用于指向指针的指针

但是*p也可以指定给指针

但不是指向指向指针的指针

那么我的问题是它们之间有区别吗

void main()
{

    int numDays;
    double sum = 0;
    double avg;
    cout << "Enter the number of days of sales";
    cin >> numDays;
    double *Sales = new double[numDays];
    double *p = Sales;
    for (int i = 0; i < numDays; i++)
    {
        cout << "enter how much you sold for day " << i << endl;
        cin >> *p;
        sum = sum + *p;
        p++;


    }


    avg = sum / (numDays);
    cout << "the sum is" << sum << endl;
    cout << "the avg is" << avg << endl;

    delete[]Sales;

指针->值

int ** ptr

指针->指针->值

是。常规的
int*
指向内存中的一组int。一个
int**
指向内存中一组int的指针…一个
int**
可能重复的@miliesmith实际上是一个
int**
指向一定数量的指针,其中每个指针指向一定数量的
int
@miliesmith-一个
int**
指向内存中的一组(如1个或更多个)
int*
s。那些
int*
s可能指向也可能不指向
int
s。例如,它们可能都是空的,在这种情况下,它们不会指向任何地方。@DanielJour technicalities。
int ** ptr