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?
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 );
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