Pascal - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Pascal Variables

Pascal Variables

shape Description

The different memory locations where data resides are called objects. To access such an object it must have a name, and such a named object is called a Variable. The information stored inside an object is called as a value. Of course the machine itself typically has no idea how to interpret the information it contains, but the program certainly needs to know. For this reason a variable has a specific type. And it’s this type that constrains the use of that variable, such that only operations appropriate to the type may be performed. The following are regular using data types of pascal language.

Declaration Of Variables

shape Description

All the variables must be announced before utilize in Pascal code. Every variable assertion are trailed by the keyword var. An announcement determines a rundown of factors, trailed by a colon (:) and the sort. The following is the syntax to declare. [c]var variable_list : type;[/c] The following is an example. [c]var java, pascal : string;[/c] The type statement demonstrates the classification or class of the sorts, for example, real, number etc. while the variable shows the kind of qualities a variable may take. User can contrast declaration of the type in Pascal with typedef in C.

Initialization Of Variable

shape Description

Naturally, the variables in Pascal does not instated with zero that may contain garbage values. So it is a superior practice to instate factors in a program. The variables can be instated in their affirmation. The initialization is trailed by the var catchphrase as follows. [c]Age: integer = 23; Section: char = 'A'; name: string = 'SPlessons';[/c] In the above example, integer and char are the data types, Age , Section are the variables. The following is an example description image. The following is an example which shows the above theory practically. SPlesson.pas [c]program SPlesson; const ALERT = ' Welcome To SPlessons '; type name = string; var author, technology: name; begin writeln('Please enter author name: '); readln(author); writeln('Please enter technology: '); readln(technology); writeln; writeln(ALERT, ' ', author, ' ', technology); end.[/c] In the above example, writeln is used to print the statement that 'Please enter author name ' and 'Please enter technology'. The readln is used to read the enterd technology. Output: Now compile the code result will be as follows. [c] Please enter author name: Sam Please enter technology: JAVA Welcome To SPlessons Sam JAVA[/c]

Summary

shape Key Points

  • The var is the keyword that used to declare a variable.
  • The pascal is not a case sensitive language.
  • The variable is not immutable in any programming language.