QBASIC CONSTANTS AND VARIABLES

Here, we will learn about **QBasic constant**, **QBasic variables** and **QBasic operators** with examples. the concept of constant, variable and different operators is very essential for the understanding of any programming language.

As a beginner you will need the same concept of Qbasic variables and constants and also know about the Qbasic operators to do different mathematical and logical **programming in QBasic**.

## What are QBasic Constants?

The value that does not change during the time of execution of a program is called Constant.

Constants are of **two types**:

### 1. Numeric Constants:

Any numeric value, either an integer or a real number, positive or negative is called a Numeric constant.** For example**: 224, + 12, 0, – 7.4 are valid numeric constants. These constants are used for calculations, and should not include any special character.

### 2. Alphanumeric or String Constants:

A set of characters is called a String. An alphanumeric or string constant consists of a sequence of alphabet and numerical characters, A – Z, a – z, 0 – 9 and special symbols, like % ? & * ( ) ; # ^ ” ‘ : / \, etc., which are enclosed in double-quotes. String constants are used to represent non-numeric quantities, such as names, text, etc.

** For example**, “JOHN”, “SUM = 84”, “192”, are some valid string constants.

## What is QBasic Variable?

A variable can be defined as a location in the memory, which has been assigned a name and is used to store data temporarily. A variable will continue to hold the value until another value is assigned to it.

There are **two** types of variables:

### 1. Numeric Variables:

A numeric variable can hold only numeric value. It is represented by an alphabet followed by either another alphabet or a digit. It should not contain any space or symbols, like A, ?, \, /, @, ;, : ,etc. Underscore can be used instead of space. For example, A, C, A2, ABC, A_6, etc., represent numeric variables in QBasic.

### 2. Alphanumeric or String Variables:

A string variable is represented by an alphabet followed by a dollar ($) sign. It can also contain letters, digits, underscore symbol, and the last character is always a dollar ($) sign. For example, A1$, RKL$, COMPU1$, etc., are valid qbasic string variables. A string variable in QBasic can also store string constant.

**For Example,** A1$ (**String Variable**) and “john” (**String Constant**)

## What is QBASIC Operator?

Operators in Qbasic perform different mathematical, logical and comparison operations.

There are** three types of operators** in QBasic:

### 1. Arithmetic Operators:

A computer performs many arithmetic operations and calculations with the help of arithmetic operators. The basic QBasic arithmetic operators are given in the following table:

### 2. Relational Operators

These operators are used to compare two values using any of the given relational operators. This can be called a QBasic comparison operator. Below is an image of all the qbasic relational operators:

### 3. Logical Operators

Logical operators are used to perform logical operations on numeric values. QBasic Logical operators are used to combine two or more relational expressions and return a single value as TRUE or FALSE in a decision. The logical operators are: AND, OR, NOT.

Below is an image of all the QBasic logical operators:

## HIERARCHY OF OPERATIONS in QBASIC

QBasic hierarchy defines the order in which the operators are executed in any Qbasic expression. It uses BEDMAS for the hierarchy of operation.

**STEPS OF SOLVING**

- First, the bracket will be solved.
- Then, the exponentiation will be performed.
- Now multiplication and division will be performed.
- Now, addition and subtraction will be performed.

Check the expression below to see how it was solved using the BEDMAS rule in QBasic.

12*4+(14+4)+2^2-12/6 #the bracket will be solved.

12*4+18+2^2-12/6 #the exponentiation will be performed.

12*4+18+4-12/6 #multiplication and division will be performed.

48+18+4-2 #addition will be performed.

70-2 #subtraction will be performed

68

Once you understand the basic concept of qbasic constants, variables, and operators, do check about “**what are qbasic QB64 statements and commands?**“. These qbasic statements and commands will help you to write QBasic programs using the built-in qbasic programming syntax.

And here is a list of simple Qbasic Programming Examples and Exercises that will help you write simple mathematical programs.

**FAQ on Qbasic Variable, Constant and Operators **

## What are arithmetic operators in Qbasic programming?

A computer performs many arithmetic operations and calculations with the help of arithmetic operators.

## What are logical operators in Qbasic?

Logical operators are used to perform logical operations on numeric values. QBasic Logical operators are used to combine two or more relational expressions and return a single value as TRUE or FALSE in a decision. The logical operators are: AND, OR, NOT.

## What do u mean by variable?

A variable can be defined as a location in the memory, which has been assigned a name and is used to store data temporarily. A variable will continue to hold the value until another value is assigned to it.

## What are relational operators in basic?

These operators are used to compare two values using any of the given relational operators. This can be called a QBasic comparison operator.