INTERVIEW QUESTIONS
C
ARRAYS IN C
DETAILS
Question: Can the sizeof 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.
|
Question:
Can the sizeof 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. Source: CoolInterview.com
YES.You can tell how large the array is. However, you cannot determine how many elements have been copied into it so far.
EX: Take for instance the following code.
int testList[5]; int sizeofList = sizeof(testList); printf("sizeof list = %d", sizeofList);
The output will be: "sizeof list = 20" Meaning that 4(int) * 5 = 20. Source: CoolInterview.com
Answered by: BJ | Date: 3/23/2008
| Contact BJ
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|