Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pascal

What are Pascal variables?

Rehan Butt

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

A variable is like a container that stores some value and maps it on the memory with a specific name to access it. The variable should be declared before using it. It is a good practice to initialize each variable with a default value to remove garbage.

Data types

Pascal provides several intrinsic data types. However, we can derive our own data types as well.

The data types of variables in Pascal are as follows::

  • Integer: An integer data type variable holds a value that is a whole number.
  • Character: A character data type variable carries a single character.
  • Real: A real data type variable has a value that is a floating point number.
  • Boolean: A boolean variable carries only two values, either true or false.

Syntax

The syntax for variable declaration is given below:

var
variable_list : type;
Variable declaration

Code example

The following example shows how to initialize and declare the variable in Pascal:

program task;
var number1 : integer;
letter : char;
begin
number1 := 23;
letter := 'W';
writeln(' ');
writeln('****************************');
writeln('OUTPUT :number1 = ', number1);
writeln(' letter = ', letter);
writeln('****************************');
end.
Initilizing , declaring and displaying the value of variables

Code explanation

  • Line 1: We name the program.
  • Lines 2 and 3: We declare variables named number1 and letter .
  • Line 4: We begin the program.
  • Lines 5 and 6: We assign values to variables.
  • Lines 9 and 10: We display the values of variables to the console.
  • Line 12: We end the program.

Note: The following warning will appear:

/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?

It can be ignored. It has been fixed in the development build FPC version 3.1.1 and latest, which have not been released officially.

RELATED TAGS

pascal

CONTRIBUTOR

Rehan Butt
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring