This section contains 269 words (approx. 1 page at 300 words per page) |
A string variable is a set of alphabetical or alphanumeric characters used to represent a value. Examples of string variable are firstname, first_name, 1_name, 1stname, 1st_name. The string variable is invaluable to computer programming. For example, let's say that Joe Smith had to write a program that printed his students' last name, first name and social security number for his math class. Depending on the computer program he was using, his string variables might be first_name, last_name and ss_number. After writing his program, he would enter all of the students' names and social security number. The program would read the data that he entered and then print out the students' names and social security numbers in the ordered specificed.
- Jones, Matt, 123-456-7895
- Anderson, Marian, 456-123-7895
- Simon, Paul, 896-456-4568
- Hines, Duncan, 897-546-1235
- Simpson, Bart, 456-357-9861
Here is Joe's program.
- Open Mathclass
- ...
- Read last_name, first_name, ss_number
- Print last_name, first_name, ss_number
- ...
- End
Without string variables, Joe's program would look like this.
- Read Jones, Matt, 123-456-7895
- Print Jones, Matt, 123-456-7895
- Read Anderson, Marian, 456-123-7895
- Print Anderson, Marian, 456-123-7895
- Read Simon, Paul, 896-456-4568
- Print Simon, Paul, 896-456-4568
- Read Hines, Duncan, 897-546-1235
- Print Hines, Duncan, 897-546-1235
- Read Simpson, Bart, 456-357-9861
- Print Simpson, Bart, 456-357-9861
- ...
- End
Also, Joe would have to create the same program for each of his 7 classes. With the string variable, he only has to create one program, and he only has to create one data file for each class as opposed to 7 programs.
This section contains 269 words (approx. 1 page at 300 words per page) |