Passing a char pointer array to a function

前端 未结 2 1090
野性不改
野性不改 2021-01-21 02:24

I have written following sample code to demonstrate my problem

#include 
#include 

using namespace std;

void f (char*** a)
{
           


        
2条回答
  •  攒了一身酷
    2021-01-21 02:58

    It's because of the operator precedence, where the array-indexing operator [] have higher precedence than the dereference operator *.

    So the expression *a[0] is really, from the compilers point of view, the same as *(a[0]), which is not what you want.

    You have to explicitly add parentheses to change the precedence:

    (*a)[0] = ...
    

提交回复
热议问题