OUTPUT :Code:include<conio.h> #include<stdio.h> void main() { int number = 100; int *numPtr =(&numPtr); clrscr(); //sorry for the wrong positioning earlier :( if(numPtr == *numPtr) { printf("wow!!!"); } printf("hello!!! mr. %d %d %d",++*numPtr,numPtr,numPtr+1); getch(); }
hello!!! mr. -13 -14 -12
Query 1 : Why is "wow" not printed?...The pointer 'numPtr' contains its own address(since it points to itself), and since the dereference happens on this 'self pointer' (*numPtr), it refers to the contents of 'numPtr' . Then why does it not print "wow"?
When i replace the above 'if' statement with 'if(numPtr != *numPtr)', amazingly the "wow" is again not printed?
Query 2:
The output too is confusing.
My numPtr somehow gets the value -14(ok...fine).
' ++*numPtr ' does -14+1 = -13(fine..again)
Now printing ' numPtr ' should give me -13(the address it contains, but the output shows -14)
Lets assume ' numPtr ' contains -14. Now ' numPtr+1 ' should give -13, but the output gives me -12.
Please help! . Am i making some basic conceptual mistake?
Thanks in advance