c - Why the following code prints 1 as output? -



c - Why the following code prints 1 as output? -

difference of pointer gives 1 output..

#include<string.h> #include<stdio.h> int main() { int a=5,b=10; int *p=&a,*q=&b; int c=p-q; printf("%d",c); homecoming 0; }

subtracting 2 pointers not pointing same array create no sense.

c11: 6.5.6 additive operators (p8)

[...] if both pointer operand , result point elements of same array object, or 1 past lastly element of array object, evaluation shall not produce overflow; otherwise, behavior undefined.

c pointers

Comments

Popular posts from this blog

python - How to add an model instance to a django queryset? -

Using Android Volley to post an array to PHP -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -