Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Is it undefined behaviour to just make a pointer point outside boundaries of an array without dereferencing it?
Post
Is it undefined behaviour to just make a pointer point outside boundaries of an array without dereferencing it?
+6
−0
I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code:
int main(void)
{
char arr[10];
char *ptr = &arr[-1];
char c = *ptr;
}
The line char c = *ptr
is obviously bad, because it's accessing out of bounds. But I heard something that even the second line char *ptr = &arr[-1]
invokes undefined behaviour? Is this true? What does the standard say?
1 comment thread