What I could understand is that the function that generates a random array returns the address of the array, and what I can't get to work is the function that receives that address and gets the array's values from it.
My understanding of pointers is really shallow as I've only started working with them recently, if someone could clarify this (as if I were a 5 year old please) and help me make the program work I'd be grateful.
I know doing it all in main would be simpler but I wanted to do it like this to try getting a better understanding of pointers and whatnot, also these functions will help me in other simple exercises.
#include<stdio.h>
#include<stdlib.h>
int* random_array(){
int size = rand()%100;
if(size == 0){
size = 1;
}
int array[size];
for(int i = 0; i < size; i++){
array[i] = rand()%100;
}
return array;
}
read_backwards(int* a){ //this is where it gets confusing
int size = sizeof(a)/sizeof(int);
if(size > 100){
size = 100;
}
int array[size] = &a;
int i = size;
while(array[i] > 0){
printf("%d", array[i]);
i--;
}
}
main(){
read_backwards(random_array());
}