Chapter-15: Variables, Constant and Data Types
1. Fill in the blanks:
(a) A variable name must have 1 to 40 characters. (b) A variable name must start with an alphabet. (c) Keywords of QBASIC are not allowed to use as a variable name. (d) A variable can be declared implicitly and explicitly. (e) Explicit declaration of variables is done with DIM statements. (f) A symbolic constant is a symbol or a variable name, which represents only one value throughout the program. (g) Data types of QBASIC are : numeric and String. (h) Different numeric data types of QBASIC are sting, integer, single precision and double precision.2. State true or false :
(a) Symbol "%" is used for integer variable. True (b) A keyword can be used as a variable name. False (c) One variable can store only one value at a time. True (d) The string cannot be used in arithmetic calculations. True (e) It is good practice to declare variables at the beginning of a program. True (f) The legal range for integer data type is from -32,767 to 32,768. False (h) 'DIM N AS INTEGER' is an example of explicit declaration of variable. True3. Write whether the given variables are valid or invalid , give reasons, if invalid:
Variables | Reasons |
---|---|
1N$ | Invalid, because start with number. |
N$ | Valid, because start with the alphabet. |
N%1 | Invalid, because of type declaration in middle. |
LET | Invalid, because LET is a keyword. |
FIRST NAME | Invalid, because of its blank space. |
FNAME | Valid, because it is a meaningful variable name. |
4. Find out whether the following assignments are valid or invalid. Give reasons if invalid:
Variables | Reasons |
---|---|
N$=KATHMANDU | Invalid, because string data is not enclosed in double quotation mark. |
N= Rs. 2000 | Invalid, because numeric data only consist digit. |
%N=2000 | Invalid, because start with type declaration. |
N1=2,000 | Invalid, because number with a comma. |
SAL= "2000" | Invalid, because numeric variable with a string data. |
N$= "Nepal" | Valid, because string data is enclosed in double quotation mark. |
1N=200 | Invalid, because variable name start with a digit. |
5. Answer the following questions:
(a) Define variables and constants with examples. Answer: Variable: An identifier or reference or name for the memory address that holds data and can change its value during the execution of a program is called variable. Example of variable: Countryname$ , Age etc. Constant: Those values, which are remained fixed during the execution of a program is called constant. Example of constant: Conuntryname$ = "NEPAL" and Age = 15 etc. (b) Write any three rules of writing a variable name. Answer: 3 rules for variable naming are as follows: - A variable name must start with an alphabet ( A to Z or a to z). - A variable name may have 1 to 40 characters in length. - Reserved word or keyword of QBASIC are not allowed to use as a variable name. (c) What are the different types of data supported by QBASIC? Explain in short with their declaration symbols and memory consumption. Answer:Data Type | Declaration Symbol | Data Range | Memory Consumption |
---|---|---|---|
String | $ eg. N$ , N1$ | 0 to 32,767 Characters | 4 bytes for descriptor, 1 byte for each character in string |
Integer | % eg. N% , N1% | -32,768 to 32,767 | 2 bytes |
Long Integer | & eg. N&, N1& | -2,147,483,648 to 2,147,483,647 | 4 bytes |
Single Precision | ! eg. N! , N1! | Accuracy up to 7 digits | 4 bytes |
Double Precision | # eg. N# , N1# | Accuracy up to 15 digits | 8 bytes |
No comments:
Post a Comment