Variables
Variable in QBASIC are the container that holds certain value. The value of variable can change depending on conditions or on information passed to the program while executing. Variable represents storage locations in the computer’s memory.
age = 18
Variable Types
1. Numeric Variable
Numeric variable can be a single letter of alphabet followed by one numerals. Numeri variable only holds numeral values.
age = 18
number = 18.9
2. String Variable
The string variable has a string of characters or alphanumeric as its value. It must begin with an alphabet and ends with a dolor ($) sign. The mathematical calculation cannot be performed using string variables.
name$ = "RAM"
Constant
Constants are the identifier like variable but the value of constant never change during the execution of program. It is declared with CONST keyword.
Types of Constant
Numeric Constant
Numeric constants are the numbers on which mathematical operation such as addition, subtraction etc. can be performed. In QBasic they can’t contain commas.
CONST pie = 3.141
String Constant
A string constant is a set of characters enclosed within double quotes. This is usually used to represent non-numeric quantities like name, address, etc. The maximum length of the string constant is 254 characters.
CONST city$ = "Delhi"
What is the Difference between Variable & Constant in Qbasic ?
Variable | Constant |
A storage location that holds data that can change during program execution. | A fixed value that does not change during program execution. |
Can be modified at any time in the program. | Remains the same throughout the program. |
Declared using DIM statement or directly assigned. | Declared using the CONST statement. |
Used to store values that might change, like user input or calculations. | Used for fixed values like mathematical constants (e.g., π, gravity). |
Examples: DIM x AS INTEGER x = 10 x = x + 5 | Examples: CONST PI = 3.14 CONST MAXLIMIT = 100 |