Follow Us on:
  • Home
  • About Us
  • Staff
  • Current Events
  • Forum
  • Tutorials
    • C Language>
      • Operators
      • Data Types
      • Decision Making
      • Looping Statements
      • Gotoxy and Textcolor
      • Array
    • Java
    • HTML/XHTML
    • CSS>
      • CSS Syntax
      • CSS Id and Class
      • CSS How To
    • Photoshop
    • Visual Basic
    • CPP Programming
  • Resources
  • Downloads

C Language

Array

Array is a collection of same type elements under the same variable identifier referenced by index number. Arrays are widely used within programming for different purposes such as sorting, searching and etc. Arrays allow you to store a group of data of a single type. 

Arrays are efficient and useful for performing operations . You can use them to store a set of high scores in a video game, a 2 dimensional map layout, or store the coordinates of a multi-dimensional matrix for linear algebra calculations.

Arrays are of two types single dimension array and multi-dimension array.  Each of these array type can be of either static array or dynamic array. Static arrays have their sizes declared from the start and the size cannot be changed after declaration. Dynamic arrays that allow you to dynamically change their size at runtime, but they require more advanced techniques such as pointers and memory allocation.   
Example: "SINGLE DIMENSION ARRAY"
           
#include <stdio.h>
#define null ' '

int main()
{
  int x,y,h,v;
  int array[] = {1,2,3,4,5,6,7,8,9,10};
  char title[] = {"PRINT SERIES OF NUMBERS"};
  clrscr();

  h = 50;
  h -= strlen(title);
  v = 2;

  gotoxy(h,v);printf("%s\n\n",title );

    for(x=0;x<10;x++)
    {
    printf("%d\t", array[x] );
    }
  getch();
}
Picture
OUTPUT: SINGLE DIMENSION ARRAY
Example: "MULTI-DIMENSION ARRAY"

#include <stdio.h>
#define p printf
#define s scanf
#define null ' '


int main() {
    char customer[3][30] = {null}; /*first index shows number of elements*/
                                               /*second index shows length of the string*/
    int i;
    
    clrscr();

    p("\n\nFirst Name: ");
    s("%s",customer[0]);
    p("Last Name: ");
    s("%s",customer[1]);
    p("City: ");
    s("%s",customer[2]);
    
    p("%s %s %s ",customer[0],customer[1],customer[2]);

    getch();
return 0;
}
Picture
OUTPUT: MULTI-DIMENSION ARRAY

Quick Links

Operators
Data Types
Decision Making
Looping Statements
Gotoxy & Textcolor
Array
Copyright Elite CSDP Society 2011 All Rights Reserved
Webmaster: Jerusalem Fonseca