Elements of QBASIC language are:
- Character Set
- Constants
- Variables
- Operators
- Expressions
1.Character Set: The set of valid characters that a language can be recognize. A character include alphabets, numbers and special characters.
2. Constants: The data items that never change their value during the execution of a program. There are two types of constants:- Numeric and String.
-Numeric Constants: They are positive or negative numbers on which addition, subtraction, multiplication and division can be performed and they do not contain commas(,). Eg:450, -742
– String Constants: They are a set of alphanumeric or special characters which is enclosed with double quote(“) Eg: “I live in Kathmandu”, “Roll no: 007” etc
3. Variables: It is the storage area whose contents can vary during the processing of the program. A variable represent a value in a program. A value of program can be changed during the execution of program.
properties of Variables:
- Any variable name can be up to 40 characters long.
- A variable name can have alphabets, numbers and decimal but cannot be kept reserved words.
- Variable name must be begin with a letter but not with fn or FN as it represents function call. eg: “fnname”.
There are two types of variable:
-Numeric Variable: It stores only numeric values. It is declared as:
Integer and long integers: Integer value is declared by using percent sign(%) as the last character of the variable name. It is stored as 2 bytes ranging from -32768 to +32767 and Long integer is declared by using ampersand sign (&), it is stored in 4 bytes ranging in values from -2,147,483,648 to +2,147,483,647
Single precision variable: It is declared by using an exclamation (!) sign. It is default numeric value and it can be used without declaration sign. Eg: MarksOfComputer!, SumOfTwoNumbers! etc.
Double precision variable: It is declared by using hash(#) sign. It can also store number with decimal points. Eg: KathmanduJhapaDistance#, CapitalOfProvinceOne# etc.
-String Variable: It stores a string constant or alphanumeric data, the last character of a string must be dollar sign($). Eg: LET Name$=”Nepal”, LET DOB$=”1989″ etc
4. Operators: They are the symbols that performs operations on the operands. It refers to be a symbol which represents what type of operations has to be performed.
-Arithmetic Operators: It performs mathematical calculation like addition, subtraction, multiplication and division, MOD represents modular division.
– Relational Operators: It is used to perform more than two values of same type either numeric or string. The result of the operation may be either True or False. Eg: =, >, <, >=, <=, <>.
-Logical Operators: It combines the result of two or more than two relational operators as a singles and gives either TRUE or FALSE. Eg: AND, OR, NOT.
AND represents multiplication of two numbers.
OR represents addition of two numbers
NOT represents just opposite to each other i.e it returns TRUE if the result is FALSE.
-String Operator: It joins more than two string data, plus(+) sign is used. The action of combining two string is called concatenation. Eg: “Roll No” and “007” results as “Roll No 007”.
5. Expressions: It is the combination of operators, constants and variables that evaluated to get a result.