Variables must be defined by type in most languages.

by Solitaire (Login Solitaire1)
S

 

The DIM stands for "Dimension" meaning size. It reserves a certain number of bytes in memory depending on the type of data. For example, the INTEGER type uses 2 bytes; LONG and SINGLE use 4 bytes; and DOUBLE uses 8 bytes of memory. Number types use stack memory but STRING uses heap memory, consuming 1 byte for each character plus overhead.

QBasic allows variables to be used without declaring them first by type. Instead of using DIM, it is also possible to add a type suffix to a variable name. For example, INTEGER variables may end with %, SINGLE ends with !, LONG ends with &, and DOUBLE ends with #. Numbers are given type SINGLE (4 bytes) by default, unless you declare them otherwise or use the suffix. But STRING variables require the $ suffix unless you declare them with DIM. You may continue using the suffix after a variable name whether or not you DIM it first, but the suffix may not be used with the DIM statement itself.

Other languages (expecially C and C++) require type declaration before the variables can be assigned, so it's a good idea to get used to using it if you are serious about continuing with the study of programming.

Posted on Feb 27, 2011, 1:11 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
Thanks!HC on Feb 27

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement