"marsarden" <> writes:
> --------pq.c--------
> #include <stdio.h>
> void main()
Find yourself a chalkboard and a piece of chalk (a whiteboard and a
marker will do if necessary). Write 100 times:
"main() returns int."
Change the line to "int main(void)".
> {
> int a=2,*p,*q;
> p=&a;q=&a;
Ok, p and q both point to a, which has the value 2.
> printf("%d %d\n",*p++,*(q++));
This should always print "2 2". You increment both pointers after
dereferencing them, which is fairly pointless, but it's harmless.
> printf("%d\n",a);
This will print "2".
> p=&a;q=&a;
Now p and q both point to a again.
> printf("%d %d\n",*p,(*q)++);
Here the third argument increments the object that q points to (namely a).
But as for any function call, the order of evaluation of the arguments
is unspecified.
Finally, since main() returns int, you should have a "return 0;" here.
> }
> -----------------------------------------
> in gcc it output:
>
> 2 2
> 2
> 3 2
>
> in vc6 it output:
> 2 2
> 2
> 2 2
Since the order of evaluation is unspecified, both results are valid.
If you care about the output, write the call so that it will work
properly and consistently regardless of the order of evaluation of the
arguments. For example, do the increment before or after the call,
not in the middle of it. If you keep your code simple and readable,
you don't have to *care* about details like this.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.