Variable Declarations

From your experience with Maple you should already be familiar with the concept of a variable. You know that a variable is a named storage location. You know that you can store a value in a variable, and that you can later examine and use that value.

Like Maple, C allows you to use variables. But unlike Maple, in which you can ``make up'' new variables as you go along, with C you have to declare all of the variables that you are going to use in your program.

In other words, before you can use a variable in a C program, you have to tell the compiler something about that variable. Can you think of the things that you would have to declare about a variable?

Click here for the answer.

This is a very important difference between Maple variables and C variables. In Maple, every variable can hold any kind of data--integers, real numbers, complex numbers, whatever. But in C, each variable is defined to hold exactly one kind of data. For example, a variable named x might be able to hold integers, or it might be able to hold real numbers, but it can't hold both kinds of numbers.

Eric N. Eide
Hamlet Project
Department of Computer Science
University of Utah