#include<stdio.h>
main()
{
int *p,*q;
p=(int *)1000;
q=(int *)2000;
printf("q-p : %d",(q-p));
return 0;
}
what the output will be and how????
|
Full Version: Pointers Question
#include<stdio.h>
main() { int *p,*q; p=(int *)1000; q=(int *)2000; printf("q-p : %d",(q-p)); return 0; } what the output will be and how????
output: q-p : 250 reason: pointer subtraction, as p and q are memory addresses, it gives u the number of objects between q and p and the object that p points to. these 2 pointers by themselves dont mean much, that is why the output also doesnt mean much, but a practical use of this is in arrays. example
output of this example is 3, which is the no. of indexes element 5 is from element 2 also note that if you want to get the integer values this is one way to access them
will give you the answer 1000 if you wanted to do integer subtraction
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
|
||||