9

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

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[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]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].