I am attempting to pass, by reference, a 1-D array of characters to a function. Here is the relevant code:
void function1();
void function2(struct template *);
struct template{
char array[11];
};
function1()
{
struct template myStruct = {0}; //initializing
function2(&myStruct);
}
function2(struct template *myStruct)
{
void writeToArray(char array[11]); //locally declaring a function
writeToArray(myStruct->array);
}
void writeToArray(char array[11])
{
/*** stuff ****/
}
Now, when debugging this code, I get an unexpected result. Once I have entered writeToArray(), I call
p sizeof(array)
which returns 4. Shouldn't a value of 11 be returned?
I am aware that the "sizeof" for all variables is statically set at compile time. So why is the compiler considering "char array[11]" of writeToArray() to be size==4?