Fun and games with ++ operators

John Murray murray at vs2.scri.fsu.edu
Wed Sep 26 00:45:29 AEST 1990


In article <9009211942.AA07458 at banach.aca.mcc.com> nong at mcc.com writes:
>
>>		#include <stdio.h>
>>		int a [2];
>>		main()
>>		{
>>			int i;
>>			a[0] = 5;
>>			a[1] = 6;
>>			i = 0;
>>			printf("%d %d\n", a[i++], a[i++]);
>>		}
>
>According to K&R ( p 59 1st edition, or 63 2nd edition )
>" The commas that separate function arguments, variables in declarations,
>etc., are not comma operators, and do not guarantee left to right evaluation."
>
>In this case the arguments may be evaluated in parallel.  It'll be interesting
>to see if i is printed as the last variable in the same print statment, will
>it be 0.

#include <stdio.h>
int a [3];
main()
{
    int i;
    a[0] = 5;
    a[1] = 6;
    a[2] = 7;
    i = 0;
    printf("%d %d %d\n", a[++i], a[++i], i);
    printf("%d\n", i);
}

output:
7 7 2
2

(output with - printf("%d %d %d\n", a[i++], a[i++], i); - was 5 5 0)

Hyuk, Hyuk, Hyuk....

240GTX / 3.3 / mips version 2.0

>______________
>Nong Tarlton
>Microelectonics and Computer Technology Corporation
>nong at mcc.com

John R. Murray          | "They call me Mr. Know-it-all, I am so eloquent.
murray at vs2.scri.fsu.edu |  Perfection is my middle name!
                        |   ...and whatever rhymes with 'eloquent'." - Primus



More information about the Comp.sys.sgi mailing list