Information need of computer programs

Long term information (memory) and short term information (memory):

  • A computer program processes information (data)

  • There are 2 categories of information (data):

      • Long term information that are used by multiple functions/methods

      • Short term information that are used by one function/method

  • Programming languages provide different kinds of variables to accommodate the information need of computer programs

    Java:

      • Class variables             
      • Local variables
      • ...

Review: the kinds of variables in a Java program

A Java program can define 4 kinds of variables:

Each kind of variables has is own scoping rules and life time

The kinds of variables in a C program

A C program can define 5 kinds of variables:

Each kind of variables has is own scoping rules and life time

The kinds of variables in a C program

Local variables and parameter variables are defined inside a function definition:

 

The kinds of variables in a C program

Local variables and parameter variables store short term information

Local variables and parameter variables are only accessible inside their own function

The kinds of variables in a C program

Global variables are defined outside all function definitions:

 

The kinds of variables in a C program

Global variables store long term information

Global variables are only accessible by all function

The kinds of variables in a C program

Static local variables are defined inside a function using the keyword static:

 

The kinds of variables in a C program

Static local variables store long term information

Static local variables are only accessible inside their own function

The kinds of variables in a C program

Static global variables are defined outside all function definitions with keyword static:

 

The kinds of variables in a C program

Static global variables store long term information

Static global variables are only accessible by functions inside their own program file