<< Chapter < Page Chapter >> Page >

Đặc tả giá trị: Tập hợp các giá trị nguyên được xác định theo dạng là một tập hợp con có thứ tự hữu hạn của tập vô hạn các số nguyên đã được nghiên cứu trong toán học. Giá trị nguyên lớn nhất đôi khi được biểu diễn như là một hằng xác định. Ví dụ trong Pascal là hằng MaxInt. Miền giá trị của kiểu số nguyên là tập các số nguyên từ -MaxInt đến MaxInt. Giá trị MaxInt được lựa chọn phản ánh giá trị nguyên lớn nhất có thể biểu diễn được trong phần cứng.

Ðặc tả các phép toán: Trên ÐTDL nguyên thường có các nhóm phép toán chính như sau:

1.- Các phép tính số học

Các phép tính số học hai ngôi thường được định nghĩa là:

Bin_Op: Integer x Integer ->Integer.

Ở đây Bin_Op có thể là cộng (+), trừ (-), nhân (*), chia (/ hoặc DIV), lấy phần dư (MOD) hoặc một số phép toán tương tự khác.

Các phép tính số học một ngôi được định nghĩa: Unary_Op : Integer ->Integer

Ở đây Unary_Op có thể là âm (-), dương (+).

Các phép toán số học phổ biến khác thường được chứa trong thư viện chương trình con.

2.- Các phép toán quan hệ

Các phép toán quan hệ được định nghĩa là: Rel_Op : Integer x Integer ->Boolean

Ở đây Rel_Op có thể là bằng, khác, nhỏ hơn, lớn hơn, nhỏ hơn hoặc bằng, lớn hơn hoặc bằng. Phép toán quan hệ so sánh hai giá trị dữ liệu đối số và trả về kết quả là một đối tượng dữ liệu logic (đúng hoặc sai).

3.- Gán trị

Cũng như phép gán tổng quát, phép gán của số nguyên có thể trả về (với định nghĩa: Assignment : Intger x Integer ->Integer) hoặc không trả về một giá trị (với đinh nghĩa: Assignment : Integer x Intger ->Void) .

Sự cài đặt

Kiểu dữ liệu nguyên hầu hết được cài đặt một cách trực tiếp bằng cách dùng sự biểu diễn bộ nhớ được xác định bởi phần cứng và tập hợp các phép tính số học, các phép toán quan hệ nguyên thuỷ trong phần cứng cho các số nguyên. Thông thường sự biểu diễn này sử dụng một từ trong bộ nhớ hoặc một dãy các bytes để lưu trữ một số nguyên. Chẳng hạn ngôn ngữ Pascal đã sử dụng biểu diễn số nguyên bởi 1 từ (word) trong phần cứng của máy tính để biểu diễn cho một số integer.

Miền con của số nguyên

Sự đặc tả

Kiểu miền con của kiểu dữ liệu nguyên là một kiểu dữ liệu mà tập các giá trị của nó là một dãy các giá trị nguyên trong một khoảng giới hạn đã định.

Các dạng khai báo sau thường được sử dụng:

A : 1..10 (Pascal)

A : Integer Range 1..10 (Ada)

Như vậy về thuộc tính, kiểu miền con của kiểu số nguyên, có thuộc tính của kiểu số nguyên. Về giá trị, tập các giá trị của kiểu miền con được xác định rõ trong phép khai báo và cuối cùng, kiểu miền con cho phép sử dụng tập hợp phép toán như trong kiểu số nguyên bình thường.

Sự cài đặt

Kiểu miền con được cài đặt tương tự như cài đặt kiểu số nguyên.

Lợi ích của việc sử dụng kiểu miền con

Kiểu miền con có một ưu điểm nổi bật đó là kiểm tra kiểu tốt hơn kiểu số nguyên. Việc khai báo một biến kiểu miền con cho phép kiểm tra kiểu một cách nghiêm ngặt hơn khi thực hiện lệnh gán trị cho biến. Ví dụ để lưu trữ các tháng trong một năm ta có thể sử dung biến MONTH với khai báo kiểu miền con là MONTH: 1..12 thì lệnh gán MONTH := 0 là không hợp lệ và lỗi đó được tự động tìm thấy khi biên dịch. Nhưng nếu MONTH được khai báo là Integer thì lệnh gán trên là hợp lệ và lỗi chỉ có thể được tìm ra bởi người lập trình trong quá trình chạy thử.

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ngôn ngữ lập trình. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10783/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ngôn ngữ lập trình' conversation and receive update notifications?

Ask