
Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content with what is available and a programming language normally provides facilities to build new data types from those that are predefined. A simple approach is to form aggregates such as arrays, structures, or unions. Pointers, according to C. A. R. Hoare “a step from which we may never recover,” permit us to represent and manipulate data of essentially unlimited complexity.
What exactly is a data type? We can take several points of view.
A data type is a set of values —char typically has 256 distinct values, int has many more; both
are evenly spaced and behave more or less like the natural numbers or integers
of mathematics. double once again has many more values, but they
certainly do not behave like mathematics’ real numbers.
Alternatively, we can define a data type as a set of values plus
operations to work with them. Typically, the values are what a computer can
represent, and the operations more or less reflect the available hardware
instructions. int in ANSI-C does not do too well in this respect:
the set of values may vary between machines, and operations like arithmetic
right shift may behave differently.
More complicated
examples do not fare much better. Typically we would define an element of a linear
list as a structure
typedef
struct node {
struct
node * next;
...
information ...
}
node;
and for the operations we specify function
headers like
node * head
(node * elt, const node * tail);
This approach,
however, is quite sloppy. Good programming principles dictate that we conceal
the representation of a data item and declare only the possible manipulations.
See next lesson : C : 2. Abstract Data Types (Abstract Data Types Information Hiding)
See next lesson : C : 2. Abstract Data Types (Abstract Data Types Information Hiding)
Terima kasih telah membaca artikel tentang C : 1. Data Type (Abstract Data Types Information Hiding) di blog Game Guides with Backdoor jika anda ingin menyebar luaskan artikel ini di mohon untuk mencantumkan link sebagai Sumbernya, dan bila artikel ini bermanfaat silakan bookmark halaman ini diwebbroswer anda, dengan cara menekan Ctrl + D pada tombol keyboard anda.