CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Variables

Variables are locations in a computer's memory. A typical desktop or laptop computer will have 8-32GB of memory, or eight to thirty-two billion addressable memory locations,

A typical C program will use 4 bytes to hold a single integer value, or 8 bytes to hold a single floating-point value.

Any variable can only hold a single value at any time - they do not maintain a history of past values they once had.

Naming our variables

To make programs more readable, we provide variables with simple names. We should carefully choose names to reflect the role of the variable in our programs.

  • While variable names can be almost anything (but not the same as the keywords in C) there's a simple restriction on the permitted characters in a name -

    • they must commence with an alphabetic or the underscore character (_ A-Z a-z), and
    • be followed by zero or more alphabetic, underscore or digit characters (_ A-Z a-z 0-9).

  • C variable names are case sensitive, thus:

    MYLIMIT,  mylimit,  Mylimit  and  MyLimit

    are four different variable names.

  • While not required, it's preferred that variable names do not consist entirely of uppercase characters.
    We'll consistently use uppercase-only names for constants provided by the C preprocessor, or user-defined type names:

    MAXLENGTH,  AVATAR,  BUFSIZ,  and  ROT

  • Older C compilers limited variable names to, say, 8 unique characters. Thus, for them,

    turn_nuclear_reactor_coolant_on    and    turn_nuclear_reactor_coolant_off

    are the same variable! Keep this in mind if ever developing portable code for old environments.

 


CITS2002 Systems Programming, Lecture 2, p4, 24th July 2024.