type
Books = record
title: packed array [1..50] of char;
author: packed array [1..50] of char;
subject: packed array [1..100] of char;
book_id: integer;
end;
Sr.No Control Statement & Description
1 break statement
Terminates the loop or case statement and transfers execution to the statement immediately following the loop or case statement.
2 continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
3 goto statement
Transfers control to the labeled statement. Though it is not advised to use goto statement in your program.
type
ch_array = array[char] of 1..26;
var
alphabet: ch_array;
c: char;
begin
...
for c:= 'A' to 'Z' do
alphabet[c] := ord[m];
(* the ord() function returns the ordinal values *)
Book 1 title : C Programming
Book 1 author : Nuha Ali
Book 1 subject : C Programming Tutorial
Book 1 book_id : 6495407
Book 2 title : Telecom Billing
Book 2 author : Zara Ali
Book 2 subject : Telecom Billing Tutorial
Book 2 book_id : 6495700
var
Books : record
title: packed array [1..50] of char;
author: packed array [1..50] of char;
subject: packed array [1..100] of char;
book_id: integer;
end;
Sr.No Concept & Description
1 Multi-dimensional arrays
Pascal supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.
2 Dynamic array
In this type of arrays, the initial length is zero. The actual length of the array must be set with the standard SetLength function.
3 Packed array
These arrays are bit-packed, i.e., each character or truth values are stored in consecutive bytes instead of using one storage unit, usually a word (4 bytes or more).
4 Passing arrays to subprograms
You can pass to a subprogram a pointer to an array by specifying the array's name without an index.
(* book 1 specification *)
With Book1 do
begin
title := 'C Programming';
author := 'Nuha Ali ';
subject := 'C Programming Tutorial';
book_id := 6495407;
end;
// Return the first and last character of a string
function firstAndList(s: string; out first: char; out last: char);
begin
first := s[1];
last := s[length(s)];
end;
Within the program exlocal
value of a = 100 b = 200 c = 300
Within the procedure display
Displaying the global variables a, b, and c
value of a = 30 b = 40 c = 70
Displaying the local variables x, y, and z
value of x = 10 y = 20 z = 30
Operators Operations
not Bitwise NOT
and Bitwise AND
or Bitwise OR
xor Bitwise exclusive OR
shl Bitwise shift left
shr Bitwise shift right
<< Bitwise shift left
>> Bitwise shift right
program exLocal;
var
a, b, c: integer;
begin
(* actual initialization *)
a := 10;
b := 20;
c := a + b;
writeln('value of a = ', a , ' b = ', b, ' and c = ', c);
end.
Sr.No Call Type & Description
1 Call by value
This method copies the actual value of an argument into the formal parameter of the subprogram. In this case, changes made to the parameter inside the subprogram have no effect on the argument.
2 Call by reference
This method copies the address of an argument into the formal parameter. Inside the subprogram, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument.
Sr.No Loop Type & Description
1 while-do loop
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
2 for-do loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
3 repeat-until loop
Like a while statement, except that it tests the condition at the end of the loop body.
4 nested loops
You can use one or more loop inside any another while, for or repeat until loop.
& Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12, which is 0000 1100
| Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61, which is 0011 1101
! Binary OR Operator copies a bit if it exists in either operand. Its same as | operator. (A ! B) will give 61, which is 0011 1101
~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) will give -61, which is 1100 0011 in 2's complement form due to a signed binary number.
<< Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240, which is 1111 0000
>> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15, which is 0000 1111
program exEnumeration;
type
beverage = (coffee, tea, milk, water, coke, limejuice);
var
drink:beverage;
begin
writeln('Which drink do you want?');
drink := limejuice;
writeln('You can drink ', drink);
end.
and Called Boolean AND operator. If both the operands are true, then condition becomes true. (A and B) is false.
and then It is similar to the AND operator, however, it guarantees the order in which the compiler evaluates the logical expression. Left to right and the right operands are evaluated only when necessary. (A and then B) is false.
or Called Boolean OR Operator. If any of the two operands is true, then condition becomes true. (A or B) is true.
or else It is similar to Boolean OR, however, it guarantees the order in which the compiler evaluates the logical expression. Left to right and the right operands are evaluated only when necessary. (A or else B) is true.
not Called Boolean NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. not (A and B) is true.
= Checks if the values of two operands are equal or not, if yes, then condition becomes true. (A = B) is not true.
<> Checks if the values of two operands are equal or not, if values are not equal, then condition becomes true. (A <> B) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes, then condition becomes true. (A > B) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes, then condition becomes true. (A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes, then condition becomes true. (A >= B) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes, then condition becomes true. (A <= B) is true.
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiplies both operands A * B will give 200
/ Divides numerator by denominator B / A will give 2
% Modulus Operator and remainder of after an integer division B % A will give 0
type
rfile = file of real;
ifile = file of integer;
bfile = file of boolean;
datafile = file of record
arrfile = file of array[1..4] of integer;
var
marks: arrfile;
studentdata: datafile;
rainfalldata: rfile;
tempdata: ifile;
choices: bfile;