Pointer question

T

Tim Rentsch

christian.bau said:
As an example, if you have an array of 10 characters, and p points to
the fourth of these characters, and i is an int with a defined value,
then evaluating p + i invokes undefined behaviour if i < 4 or i > 6.
(As a boundary case, evaluating p + 6 would be legal even though it
doesn't point to any existing object).

If i < 3 or i > 7 (and p+7 in the last part). If a is the array, the
fourth element is a[3]. The element a[4] is the fifth element.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top