I'm learning about pointers in C and I tried this program in GCC Compiler.
When I try p-q
it gives 1 as output (as it takes 4 bytes for int and the values of p and q are 2358844 and 2358840 respectively and hence 1 as output because 1*4=4 bytes after p-q
provides 4).
But as soon as I try q-p
it gives 4294967295 as output. It should give -1 as output, but I'm unable to understand why it is giving the other output.
This is my program.
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
int *p,*q;
p=&a;
q=&b;
printf("p = %u",p);
printf("\nq = %u",q);
printf("\nq-p = %u",q-p);
getch();
}