Home>
int len ​​(double x []) {
  int n = sizeof (x)/sizeof (x [0]);
  return n;
}
int main (void) {
  double x [] = {0,1,2,3,4};
  int n = len (x []);
I want to create a function that returns the number of elements of an array outside the main function like

, but even if I search for "how to pass a pointer" because my understanding is not enough No convincing answer was found.
I'm very happy if someone tells me.

  • Answer # 1

      

    I want to create a function that returns the number of elements in an array outside the main function

    Unfortunately, it isnotcreated as a function in C.

    sizeof (x)isbecause

    double x []has the same meaning asdouble * x>Pointer size. The pointerdoes not includeinformation about "size of the area you are pointing to".

    A macro that expands a string on the spot is possible.

Related articles