Passing Pointer To An Array Of Arrays Through Function

前端 未结 6 1832
南旧
南旧 2021-01-21 14:00

There is a pointer-to-an-Array of Arrays i.e. NameList in the code. I want the contents of each of the Arrays in the Pointer(NameList) to get printed one by one. The below co

6条回答
  •  情书的邮戳
    2021-01-21 14:39

    int Data1[]
    

    has the type of

    int *
    

    and

    int *NameList[]
    

    has the type of

    int **
    

    You have a two-dimensional array there. Most likely you meant:

    Function(int **ArrayPointer)
    

    On that note, ANSI C/C89/C99 functions have an explicit return type (or void), e.g.

    int main() { ... }
    void Function() { ... }
    

    The value pointed to by ArrayPointer is an int, not a string. Thus

    printf("\nName: %s",  ArrayPointer[index++]);
    

    Should be written as something else.

    A third thing: index == j in your code. Thus index can be removed in favor of j.

    i and j are probably not good variable names here because ArrayPointer is not name describing a list of something.

    If you need more help, please post what you're looking to do, because you code has several bugs (and oddities) in it.

提交回复
热议问题