Interviewer And Interviewee Guide

Data Structure Arrays Interview Question:

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

Submitted by: Muhammad
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 );
Submitted by: Muhammad

Read Online Data Structure Arrays Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.