Interviewer And Interviewee Guide

Data Structure Arrays Interview Question:

Explain is it valid to address one element beyond the end of an array?

Submitted by: Muhammad
It's valid to address it, but not to see what's there. (The really short answer is, "Yes, so don't worry about it.") With most compilers, if you say
int i, a[MAX], j;

then either i or j is at the part of memory just after the last element of the array. The way to see whether i or j follows the array is to compare their addresses with that of the element following the array. The way to say this in C is that either

& i == & a[ MAX ]
is true or
& a[ MAX ] == & j
is true. This isn't guaranteed; it's just the way it usually works.
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.