0
What will be output of following program ?
int main() { int a=5,b=10,c; int *p=&a, *q=&b; c=p-q; printf("%d",c); return 0; } what is the ans of above program
13 Respuestas
- 1
good to get to know that brother
thanks ..✌
+ 6
C is 3 in VC++ ide. It just tell you that a and b are 3 memory blocks apart. It is kind of platform dependant.
+ 6
Dear Shivshankar it is all about memory offset.
+ 1
@sayan
pointers don't work like normal integers, so you can't add them.
you can only add an int to then.
subtraction of two pointers will give you the number of items (int In this case) in between them, instead of the difference of the raw pointer values.
0
what is the outpur of above program
0
out put will be 1...
0
#sayan chandra how we get to 1 plzz comment fast
0
ok babak sheykhan
0
tysm sayan chandra
0
The answer is undefined. It depends on the compiler used. Will probably be 1 (or -1) but not necessarily.
- 1
the output is 1...showing...
for any values of a,b
- 1
the thing is..
its showing as &a=-12 &b=-14
p=-12 and q=-14
but c =1
- 1
but out put of p and q is -12 & -14
c=p-q
how is c=1 ???
and yes...printing c as q-p it results -1
BUT c=p+q shows invalid pointer addition