0

I am a newbie to c++ and got the following code:

#include <stdio.h>

void func(int n, double *x);

int main() 
{
      int n;
      double x[] = { 0.0, 0.0, 0.0 };

      int xsize = sizeof(x)/sizeof(double);
      printf("\n xsize in main = %i \n",xsize);

      func( n, &*x );

      return 0;      
}


void func(int n, double *x)
{
      int xsize = sizeof(x)/sizeof(double);
      printf("\n xsize in func = %i \n",xsize);
}

The output is this:

xsize in main = 3

xsize in func = 1

My question is:

Why is xsize not 3 in func, but 1 ???

Thank you very much!

1 Answers1

0

Why is xsize not 3 in func, but 1 ???

Because the function argument is a pointer. And the size of a pointer divided by the size of a double is 1 on your system and not 3.

eerorika
  • 232,697
  • 12
  • 197
  • 326