I want to pass an array as a parameter. I want the other function to calculate the array size. So array size is not passed as a parameter. How do I do this?
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
void myFunction1(int tmpints[])
{
int arraysize = *(&tmpints + 1) - tmpints;
printf("In myFunction1....\n");
printf(" size is :%d\n",arraysize);
printf(" start is :%p\n",*(&tmpints + 1));
}
void myFunction2(int tmpints[],int* EndP)
{
printf("In myFunction2....\n");
printf(" size is :%d // correct\n",EndP-tmpints);
printf(" start is :%p\n",*(&tmpints + 1));
}
int main()
{
int tmpintarray[] = {4,3,2,9,8,7};
printf("In main....\n");
printf(" start is :%p\n",*(&tmpintarray + 1));
printf(" size is :%d // correct\n",*(&tmpintarray + 1)-tmpintarray);
myFunction1(tmpintarray);
myFunction2(tmpintarray,*(&tmpintarray + 1));
}
results
In main
:
start is :0x7ffc7e593a38
size is :6 // correct
In myFunction1
:
size is :-529944200
start is :(nil)
In myFunction2
:
size is :6 // correct
start is :0x7ffc7e593a40