User Tools

Site Tools


Sidebar


Introduction


Basic Tutorials


Advance Tutorials


Useful Techniques


Examples

  • Simple Pipe Weight Calculator
  • Unit Convertor

Sidebar

tutorial:variableanddatatype

This is an old revision of the document!


Variables And Data Types

Variables

คือ ตัวแปร ที่ใช้ในการเขียนโปรแกรม การใช้งาน Variables จะต้องมีการประกาศตัวแปรก่อนเสมอ เพื่อให้ Compiler จองหน่วยความจำสำหรับตัวแปรนั้นอย่างเหมาะสม หลังจากนั้นจึงนำมาใช้ใส่ค่าหรือสั่งให้แสดงค่าได้ตามความต้องการ

การประกาศตัวแปร จะประกาศหลังจากคำว่า var โดยการใส่ชื่อตัวแปล แล้วตามด้วย DataType โดยการประกาศสามารถประกาศได้ทีละหลายตัว และยังประกาศพร้อมกับใส่ค่าเร่ิมต้นได้ เเช่นกัน ดังตัวอย่างต่อไปนี้

  Var
    x :integer;
    y,z :boolean; //multi-lines declaration
    a :real = 43.295; //declare with initial value

Data Types

แบ่งได้เป็น 4 ประเภท ดังนี้

Data Type Descriptions
Standard Type Integer
Real
Boolean
Character
String
User-define Type Enumerated
Sub range
Set
Structured Type Array
Record
Object
Class
Pointer Type Pointer

Standard Type

สรุปได้ดังนี้

Data Types Declaration/Defining
integer
var 
  x:integer;
...  
  x:=10;
Real
var 
  x:real;
...  
  x:=1.0923;
Boolean
var 
  x:boolean;
...  
  x:=true; //or false
Character
var 
  x:char;
...  
  x:='A';
String
var 
  x:string;
...  
  x:='How are you?';
tutorial/variableanddatatype.1546844826.txt.gz · Last modified: 2019/01/07 14:07 by admin