Skip to content
Variables and Types
step 1/5

Reading — step 1 of 5

Learn

~1 min readBasics

Pascal is strictly typed. Variables must be declared in a var block before the begin:

program Demo;
var
    name: string;
    age: integer;
    pi: real;
    isActive: boolean;
begin
    name := 'Ada';
    age := 36;
    pi := 3.14159;
    isActive := true;
end.

Assignment uses :=, NOT =. Equality test is =.

Common types:

  • integer (32-bit), int64 (64-bit)
  • real / double (floats)
  • boolean (true, false)
  • char (single character, single quotes)
  • string (variable-length text)

Reading stdin:

var n: integer;
begin
    ReadLn(n);
    WriteLn(n * 2);
end.

ReadLn parses based on the variable's type — int into integer, etc.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…