MCS-011 Problem Solving and Programming

First year, Semester 1

Chapters

Newsletter

Variables

Variable is an identifier whose value changes from time to time during execution. It is a named data storage location in your computer’s memory. By using a variable’s name in your program, you are, in effect, referring to the data stored there. A variable represents a single data item i.e. a numeric quantity or a character constant or a string constant. Note that a value must be assigned to the variables at some point of time in the program which is termed as assignment statement. The variable can then be accessed later in the program. If the variable is accessed before it is assigned a value, it may give garbage value. The data type of a variable doesn’t change whereas the value assigned to can change. All variables have three essential attributes:

  • the name
  • the value
  • the memory, where the value is stored.

For example, in the following C program a, b, c, d are the variables but variable e is not declared and is used before declaration. After compiling the source code and look what gives?

main() {

    int a, b, c;

    char d;

    a = 3;

    b = 5;

    c = a + b;

    d = 'a';

    e = d;

  ..........................

..........................

}

After compiling the code, this will generate the message that variable e not defined.  

Report an issue

Reporting: Variables (topic)

Related Posts