Originally Posted by
keisx
Hi! I have an array of records, now the question is - is it possible to pass whole array (100 records) with all the records with a simple variable? I doubt that it's a good idea or even if it's possible (???) - another option, in my situation, is to read all the records from a file into an array directly inside a function, which could be easier, if I'm thinking correct (and again I don't know if C will allow it, cause I'm new to this language and haven't discovered everything here yet).
We never pass an entire array in C. That's too inefficient. We pass a single pointer to the base of the array. Conveniently, that also happens to be the name of the array, itself.
The name of the array is not a pointer than can have it's address changed to something else. It's constant, and will always point to the base of it's own array.
Declare your array in the calling function, and then you can fill it in the called function. When the called function is done, the array will still be valid (not go out of scope and disappear).
try this:
Code:
#include <stdio.h>
int main(void) {
char ch, myArray[] = { "The willow rustled in the wind"};
printf("%s is at memory address %p", myArray, myArray);
printf("\n\t\t\t press enter when ready");
ch = getchar();
return 0;
}
That address is in hexadecimal, so it's not the usual numbers.