Passing two-dimensional array via pointer

前端 未结 9 1008
失恋的感觉
失恋的感觉 2020-11-28 14:04

How do I pass the m matrix to foo()? if I am not allowed to change the code or the prototype of foo()?

void foo(float **pm)
{
    int i,j;
    for (i = 0; i          


        
相关标签:
9条回答
  • 2020-11-28 14:35

    Does foo(m) not work?

    0 讨论(0)
  • 2020-11-28 14:39

    If you have a compiler that supports C99, the current C standard, then you can do this:

    foo((float *[]){ m[0], m[1], m[2], m[3] });
    

    (Note that this is exactly the same as AndreyT's answer, except that it forgoes having to name the temporary array)

    0 讨论(0)
  • 2020-11-28 14:41

    void foo(float **pm) is the same as void foo(float *pm[]) which is not a two-dimensional array of floats. It is an array of float*. Now, those float* may themselves point to float arrays, but that's a separate matter.

    0 讨论(0)
提交回复
热议问题