I'm trying to setup a pointer function that returns the adress of the first element of an array which is stored locally in itself, and then use (in this case print) the contents on another function.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <stdbool.h>
double *n(int a)
{
int i;
double array[' '];
for(i=0;i<a;i++)
{
array[i] = rand();
printf("\n element: %f \t\n\n", array[i]);
}
return array;
}
void exe()
{
double *unfixed;
int c, b, j;
scanf("%d", &b);
unfixed = n(b);
printf("\n\n Precoded acces value %f \n\n", *(unfixed + c));
for(j=0;j<b;j++)
{
printf("\n %f", *(unfixed + j));
}
return;
}
int main()
{
exe();
return 0;
}
It works properly when I refer to it by static statements, example:
printf("\n\n %f \n\n", *(unfixed + c));
On the contrary when I go ahead and try to get a cycle or decision to be made it just straight up doesn't work.
P.D.: Also for some unholy reason it works perfectly with int type pointer functions.