*str[] 和 str[][] 之间的区别

Difference between *str[] and str[][]

本文关键字:str 区别 之间      更新时间:2023-10-16

我不明白这段代码中 *str[] 的使用,它与这段代码中使用的 str[][] 有什么不同吗?

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
int main()
{
    char a[10], b[10], c, buffer[50], str[1][9], s[10];
    //decalaring char a, b, buffer, str[][], s//
    int y;
    ofstream out;
    out.open("output.cpp");
    out<<("nOPCODEtMACHINE_CODEn");
    do
    {
        y = 0;
        cout<<"ENTER THE OPCODE&MACHINE CODE";
        cin>>a>>b;
        out<<"n"<<a<<"t"<<b<<"t"<<"n";
        cout<<"PRESS 1 TO CONTINUE";
        cin>>y;
    }while(y == 1);
    out.close();
    ifstream in;
    in.open("output.cpp");
    while(in)
    {
        c = in.get();
        cout<<c;
    }
    in.close();
    cout<<"ENTER THE OPCODE TO SEARCH";
    cin>>s;
    in.open("output.cpp");
    in.getline(buffer,50);
    while(in)
    {
        *str[0] = ''; // i dont understand the use of *str[] here, is it diff from str[][]?
        *str[1] = '';
        in>>str[0];
        in>>str[1];
        if(strcmpi(str[0], s) == 0)
        {
            cout<<"n"<<str[0]<<"t"<<str[1];
        }
    }
    return 0;
}

*x的意思是"取消引用指针x"。现在,每当一个数组处于语言需要指针的位置时,它就会隐式衰减到指向第一个元素的指针。

所以

*str[0]='';

意思是"将''分配给 1 元素字符数组str[0]的第一个元素,它本身就是 9 元素数组的第一个元素str"。

它的意思与

str[0][0] = '';

可以说应该是这样写的。或者str应该首先被宣布为char str[9]