You are on page 1of 3

Naming a program A.

data types of variables


jevigyklg kula fh§u úp,H j, o;a; j¾.

a name can be assigned to a Pascal program A variable's type alerts the computer about the
before the beginning. type of data that we are going to store inside it
jevigykla wdrïNhg fmr thg my; mßÈ úp,Hl o;a; j¾.h u.ska wm úiska tys .nvd
kula fh§u isÿ l, yel lrkafka l=uK j¾.fha o;a; o hehs
mß.Klhg woyila ,ndfoa

program programName; integer a whole number


mQ¾K ixLHdjla
real a number with decimals
Variables oYu iys; ixLHd
úp,H char holds one character
tla ixfla;hla
• A temporary storage location separated in string holds a set of characters
the main memory of a computer ixfla; lsym s hla
• paired with an associated symbolic boolean holds ( true / false )
name (an identifier) ( i;H $ wi;H ) w.hka
• which can contain some quantity of
information B. declaring a variable
• of a certain data type úp,Hla iE§u

• hï o;a; j¾.hlg wh;a VariableName: DataType;


• f;dr;=re m%udKhla r|jd ;nd.; yels
• ixfla;d;aul kduhla yd hq.,kh jQ C. naming variables
^y÷kajkhla& úp,H kdulrKh
• mß.Klfhys m%Odk u;lh ;=, fjkalr.;a
;djld,sl .nvd ia:dkhla a variable name can only contain letters, digits
and underscores _ (no other special characters or
spaces are allowed inside them)
In Pascal, a sector must be separated before the úp,H kduhl mej;sh yelafla wl=re" b,lalï
beginning of a program to declare variables iy há bß muKs _ ^ta ;=< fjk;a lsisÿ úfYaI
meial,a NdYdfõ§ úp,H iE§u i|yd i,l=Kq fyda ysia wjldY mej;sh fkdyel&
jevigyk wdrïNhg fmr l,dmhla f;dard.;
hq;=h a variable name cannot be started with a digit
(can only be started with a letter or an
underscore)
úp,H kduhla b,lalulska wdrïN úh fkdyel
var ^wdrïN úh yelafla wl=rlska fyda há brlska
variables are created here muKs&
fuys§ úp,H idokq ,nhs
begin language reserved words cannot be used as
program is written here variable names
fuys§ fla;h ,shkq ,nhs NdYdfõ weúrekq mo úp,H kdu f,i Ndú;d
end l, fkdyel

Pascal is not a case sensitive language


meial,a hkq capital / simple ixfõ§ NdYdjla
fkdfõ
D. assigning values to a variable E. displaying a variable
úp,H i|yd w.hka wdfoaYh úp,Hla fmkaùu

assignment operator is used var


wdfoaY lsÍfï fufyhjkh Ndú;d lrhs k : integer ;
begin
k := 7 ;
write ( k ) ;
readln ;
end.
Assigning values char and string should be done
within single quotes to avoid confusions
jHdl+,;ajhka u.yrjd.ekSu i|yd Char iy
F. declaring multiple variables
String úp,H j,g ;ks WoD; mdG ;=, w.hka úp,H lsym s hla iE§u
wdfoaY l, hq;=h
var
Assigning values for integer, real and Boolean
variables can be done without using quotation a , b : integer ;
marks x , y : real ;
integer, real iy Boolean j¾.fha úp,H j,g begin
WoD; mdG Ndú;hlska f;drj w.hka wdfoaY
lsÍu isÿlrhs
end.

var
a : integer ;
G. reusing a variable
b : real ; tlu úp,H kej; kej; Ndú;h
c : char ;
d : string ;
var
e : boolean ;
begin a , b : integer ;
a := 7 ; begin
a := 7 ;
b := 35.8 ;
c := ‘K’ ; write ( a ) ;
a := a + 1 ;
d := ‘Ravindu’ ;
write ( a ) ;
e := True;
b := 5 ;
An expression containing the assignment b := a + b ;
operator is much better to be read from the right write ( b ) ;
side to the left readln;
wdfoaY lsÍfï fufyhjkhla wvx.= m%ldYKhla end.
ol=fKa isg jug lsheùu jvd;a iqÿiqh
Constants
ksh;

Data structures which do not change their value


from the beginning to the end of the executed
program are called constants
jevigykla l%shd;aul jk w;r;=r§ ;u
w.hka fjkia lr fkd.kakd o;a; jHqyhka
ksh; f,i ye¢kafõ

They also have an identifier


tAjdgo y÷kajk kdu mj;S

They do not have a data type


tAjdg o;a; j¾.hla fkdmj;S

They are declared in a separate section


tAjd fjku fldgila ;=, w¾:olajhs

Const
Pi = 22/7 ;
Var

Begin

End.

Values for them are assigned on the declaration


venue itself, using only the equal mark ( not the
assignment operator )
idok i:dkfha§u tAjdg w.hka wdfoaY lrk
w;r fuys§ wdfoaY lsÍfï fufyhjkh fjkqjg
iudk lsÍfï ,l=K muKla Ndú;d lrhs'

Prepared by:
Ravindu Bandaranayake

Maliyadeva College (Batch 2014 - Science)


B.Sc. Cyber Security (Undergraduate)
BCS Level 5
Dropout – SLIIT (Software Engineering)
Dropout – Wayamba University of Sri Lanka (Applied Sciences)

ict from abc


,xldfõ úYd,;u Online ICT mka;sh

visit https://ictfromabc.com to register


call 0714 555513 for more info

You might also like