14

Les variables

  1. #include <stdio.h>
  2.  
  3. main() {
  4.     int i;          /* declaration */
  5.  
  6.     int x, y;       /* several declarations (same type) */
  7.     int z = 11;     /* declaration and initialization */
  8.     int b1, b2 = 3; /* mix - not int b1 = b2 = 3 */
  9.  
  10.     x = 66;         /* assignment */
  11.     z = y = 33;     /* in a chain */
  12.  
  13.     /* confusing - to be avoided */
  14.     b2 = (b1 = b2) + 1;
  15.  
  16.     /* legal but useless */
  17.     x + y;          /* warning from compiler */
  18.     123;            /* compiler is quiet! */
  19.  
  20.     /* illegal (misplaced) - compile with -pedantic */
  21.     /*
  22.     int a;
  23.     */
  24.  
  25.     printf("i=%d\n", i);    /* value? - warning from compiler */
  26.  
  27.     printf("x=%d\n", x);
  28.     printf("y=%d\n", y);
  29.     printf("z=%d\n", z);
  30.  
  31.     printf("b1=%d, b2=%d\n", b1, b2);
  32.  
  33.     printf("b1=%d, b2=%d\n", b1 );  /* explain - value for missing argument */
  34.  
  35.     return 0;       /* explain - compare with exit(0) */
  36. }
$ 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

Votre commentaire :
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip aide 2000

Entrez un maximum de 2000 caractères.
Améliorez la présentation de votre texte avec les balises de formatage suivantes :
[p]paragraphe[/p], [b]gras[/b], [i]italique[/i], [u]souligné[/u], [s]barré[/s], [quote]citation[/quote], [pre]tel quel[/pre], [br]à la ligne,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]commande[/code], [code=langage]code source en c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].