wpe41.gif (23084 bytes)CIS3355: Business Data Structures
Fall, 2008
 

What types of array declarations are there and what do they mean?

 

                            There are 3 different array declarations in C programming.

 

 

 

 

Array Declaration #1: Automatic Arrays (local arrays)

  • Automatic arrays are defined within the function (references to other arrays cannot be made)
  • Exist only during the existence of the function
  • Not initialized
  • When done, memory allaction is freed

 

Text Box: void main()
{ int array1[100];

  

 

     Automatic Arrays are the most common types of declarations.

 

 

 

Array Declaration #2: External Arrays (global arrays)

·        Defined outside the function8

·        Known to ALL functions

·        Do NOT expire (as long as the program is running)

·        Initialized when declared (set to 0 (zero) if numeric; null if character)

 

Text Box: int array2[100];                      // array is a GLOBAL array (available to ALL
int main ()
{int index;
 


  

 

Array Declaration #3: Static Arrays

  • Like automatic arrays, local to the function which declared them
  • Like external arrays, retain values between calls
  • Like external arrays, initialized at the time of declaration (set to 0 (zero) if numeric; null if character)

 

Text Box: Int main ()
{  static int int array3[100];
    int index;
 

 

 

 

Helpful references.

Numeric and Logic Declarations

Basic C++ Utilities for Primitive Numeric Data

 

Lets try some questions!!

 

1.  Which array is local to the function?

  1. Automatic Array
  2. External Array
  3. Static Array
  4. Both A and B
  5. Both A and C
  6. Both B and C
  7. None of the above

       

    (Answer - E)

 

2.  True or False - Static Array are the most common types of arrays?

    (Answer – False, automatic arrays are the most common.)