Variables And Constants in QBasic : QBasic Tutorial

Variables and Its Types:

A variable is a symbolic unique name that occupies space in the computer memory for storing data temporarily. 

It can simply be said as a thing whose values keeps on changing during the execution of program.
A value of variable can be changed due to the execution of the programs.

Variables And Constants in QBasic

1. String Variable: 

It is a name or reference which stores alphanumeric characters. It contains dollar sign $ for example: R$, NI$ etc.

Any types of declaration characters is not allowed in variable name.

2. Numeric Variable

It is the name or reference which stores positive or negative number.  There are four type of Numeric Variable.

  • Integer- percentage sign %
  • long Integer- ampersand sign &
  • Single precision- exclamation !
  • Double precision- has tag #

Constants and Its Types:

Constants are the data of a values in a program, that may be letter, number or special characters.
It's value doesn't change during the execution of program.

1. String Constant

An alphanumeric data enclosed in double quotes is called string constant. It may be word, number, blank space, special character etc. for example: "Dhading"."Mahendranagar".

2. Numeric Constant

A number with or without decimal point that is not enclosed inside double quotes. All positive and negative and decimal numbers are numeric constants.for example: 5,-7,7426.42etc


Rules For Naming The Variable

a. Variable must be up to 40 characters long.
b. It must begin with letter.
c. Variable word cant be reserved word.

Accumulator

It is a variable in which the intermediate value of another variable is stored.It helps to find the sum of all values assigned to the particular variable.
Example
CLS
S = 0
FOR P = 1 TO 5S = S + PNEXT 
PPRINT " THE SUM IS " ; 
SEND