- #1
C0nfused
- 139
- 0
Hi everybody,
Probably some easy questions in pascal:1) what exactly is a variable?Is it just a "place" to store data? And how do we retrieve this data from variables? When we write a variable's name in an expression the value of the variable is used in this expression?For example when we have an integer variable named "x" then when we write (3*x+5) the pc retrieves the value of x and uses it to calculate the value of the expression? So the name of the variable "represents" its value?
2) When we have a boolean type variable, named for example "check" are we allowed to use it in the following way: " if check then <statement1> else <statement2> " or like this :
" while check do <statement3> " ? In these cases the variable is like a boolean expression whose value(true/false) is the value of the boolean type variable? So the above examples are the same as these:
" if (check=true) then <statement1> else <statement2> " and
" while (check=true) do <statement3> " ?
This also applies when we write "(not check")?This is the same as (check=false) ? Generally writing " check and test" (where test is another boolean type variable) is like writing "((check=true) and (test=true))" ? They are all considered boolean expressions?
And one thing about arrays: when we use an array [1..10] of integer for example named "ar" then each cell of the array(ar[1],ar[2] etc) is exactly the same as a simple integer variable? So if we have a procedure that uses a variable parameter and a value parameter, for example
" procedure sum(a:integer;var b:integer); etc " then we can call it in the main body of the porgram using two of the cells of the array as real parameters of the procedure? For example we can make this call of the above procedure: " sum(ar[1],ar[2+3]) ? This applies to any kind of arrays that have the same type of values( integer,real etc) with the type of the parameters of the procedure?
Thanks
Probably some easy questions in pascal:1) what exactly is a variable?Is it just a "place" to store data? And how do we retrieve this data from variables? When we write a variable's name in an expression the value of the variable is used in this expression?For example when we have an integer variable named "x" then when we write (3*x+5) the pc retrieves the value of x and uses it to calculate the value of the expression? So the name of the variable "represents" its value?
2) When we have a boolean type variable, named for example "check" are we allowed to use it in the following way: " if check then <statement1> else <statement2> " or like this :
" while check do <statement3> " ? In these cases the variable is like a boolean expression whose value(true/false) is the value of the boolean type variable? So the above examples are the same as these:
" if (check=true) then <statement1> else <statement2> " and
" while (check=true) do <statement3> " ?
This also applies when we write "(not check")?This is the same as (check=false) ? Generally writing " check and test" (where test is another boolean type variable) is like writing "((check=true) and (test=true))" ? They are all considered boolean expressions?
And one thing about arrays: when we use an array [1..10] of integer for example named "ar" then each cell of the array(ar[1],ar[2] etc) is exactly the same as a simple integer variable? So if we have a procedure that uses a variable parameter and a value parameter, for example
" procedure sum(a:integer;var b:integer); etc " then we can call it in the main body of the porgram using two of the cells of the array as real parameters of the procedure? For example we can make this call of the above procedure: " sum(ar[1],ar[2+3]) ? This applies to any kind of arrays that have the same type of values( integer,real etc) with the type of the parameters of the procedure?
Thanks
Last edited: