15
Les variables
- #include <stdio.h>
- main() {
- int i; /* declaration */
- int x, y; /* several declarations (same type) */
- int z = 11; /* declaration and initialization */
- int b1, b2 = 3; /* mix - not int b1 = b2 = 3 */
- x = 66; /* assignment */
- z = y = 33; /* in a chain */
- /* confusing - to be avoided */
- b2 = (b1 = b2) + 1;
- /* legal but useless */
- x + y; /* warning from compiler */
- 123; /* compiler is quiet! */
- /* illegal (misplaced) - compile with -pedantic */
- /*
- int a;
- */
- printf("i=%d\n", i); /* value? - warning from compiler */
- printf("x=%d\n", x);
- printf("y=%d\n", y);
- printf("z=%d\n", z);
- printf("b1=%d, b2=%d\n", b1, b2);
- printf("b1=%d, b2=%d\n", b1 ); /* explain - value for missing argument */
- return 0; /* explain - compare with exit(0) */
- }
$ gcc -o vars vars.c
vars.c: In function ‘main’:
vars.c:33: warning: too few arguments for format
$ ./vars
i=2723828
x=66
y=33
z=33
b1=3, b2=4
b1=3, b2=4
Commentaires