Data Structure Arrays Question:

Download Job Interview Questions and Answers PDF

Tell me can the size of operator be used to tell the size of an array passed to a function?

Arrays Interview Question
Arrays Interview Question

Answer:

No. There's no way to tell, at runtime, how many elements are in an array parameter just by looking at the array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to the first element. This is a Good Thing. It means that passing pointers and arrays to C functions is very efficient.
It also means that the programmer must use some mechanism to tell how big such an array is. There are two common ways to do that. The first method is to pass a count along with the array. This is what memcpy() does, for example:
char source[ MAX ], dest[ MAX ];
/* ... */
memcpy( dest, source, MAX );

Download Arrays Interview Questions And Answers PDF

Previous QuestionNext Question
Explain is it valid to address one element beyond the end of an array?Tell me is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?