4

Initializing a table

  1. #include <stdio.h>
  2.  
  3. #define TABSIZE 4
  4.  
  5. main() {
  6.     int tab1[ TABSIZE ] = { 1, 2, 3, 4 };
  7.     int tab2[ TABSIZE ] = { 1, 2 };
  8.     int tab3[] = { 1, 2, 3, 4, 5 };
  9.  
  10.     int i;
  11.  
  12.     for ( i = 0; i < TABSIZE; i++ )
  13.         printf("%d: %d\n", i+1, tab1[ i ]);
  14.  
  15.     printf("\n");
  16.  
  17.     for ( i = 0; i < TABSIZE; i++ )
  18.         printf("%d: %d\n", i+1, tab2[ i ]);
  19.  
  20.     printf("\n");
  21.  
  22.     for ( i = 0; i < sizeof( tab3 ) / sizeof( int ); i++ )
  23.         printf("%d: %d\n", i+1, tab3[ i ]);
  24. }

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].