Minggu, 04 April 2010

TYPES OF DATA, constants, VARIABLE, SYMBOL OF OPERATIONS, AND EXPRESSION

Indonesian to English translationShow romanization
TYPES OF DATA, constants, VARIABLE, SYMBOL OF OPERATIONS, AND EXPRESSION

Note: sorry the tables are not neat, I do not know the use of tables in this forum

Variables & constants are the basic data objects manipulated in a program. Every constant and variable data types must be clear. For that they must be declared before.

Operator (operation symbol) is used to determine what to do about the constant / variable.

Expression is a wake algorithm, based on certain rules, to calculate a value. An expression is formed by the variables, constants and functions (Operands) that combined the symbols of operations (operators).

Rules that apply in an expression is as follows
  1. an expression of the operation of the operator will put the highest level.
  2. an expression will put the operation of the first leading operators if the operators that are used have the same level.
  3. an expression that contains the operating priority (in parentheses), will advance the implementation of these priority operations.
  4. Operands used in an expression must have or produce the same type of data.


A. MAIN TYPES OF DATA
C basically only knows four kinds of words, ie char, int, float, and double.

A type of data set a value that can rentangs owned by a constant and variable, or produced by an expression or function. (Nicklaus Wirth 1976:4)

Thus, if you will use a constant, variable, or function they must set its data type, because each operation is established based on a specific data type.

Char data types is a single byte that has the ability to hold a character data. Int data types is a type of data that has the ability to hold an integer value. Float data types is a type of data that has the ability to hold a value of single precision real numbers. Double data types is a type of data that has the ability to hold a value of double precision real numbers.

Expansion of int data type embodied in the two other data types, namely short and long, distinct ability to store a range of values given to him.
Types of data types char, int, short, and long may be preceded by a signed or unsigned keyword to indicate that the type of data include negative integer or not. If it is not stated, it is considered signed.

Range of values and the size of each type of data depends on the type of machine and compiler used.

Code:

Range sizes of data types values
-------------- ------ ---------------------------
1 byte char -128 s / d 127
unsigned char 1 byte 0 to 255
2 byte signed int -32.768 s / d 32.767
2 byte unsigned int 0 s / d 65.535
2-byte short -32.768 s / d 32.767
2 byte unsigned short 0 s / d 65.535
2 bytes long -2,147,483,648 s / d 2,147,463,647
unsigned long 4 bytes 0 to 4,294,967,295
4-byte float 3.4E-38 s / d 3.4E +38
8 byte double 1.7E-308 s / d 1.7E +308

Note:
* Suffix L to be written behind the integer constants to distinguish the data type long or unsigned long data type of the other integers.
* String data type is seen as an array of characters

B. VARIABLES
Variable is a quantity whose value can change during program. Each variable is expressed by an identifier.
Each variable must be declared before used in the program. Each variable must be declared data type. The general form of declaring variables is as follows.

[type] id_var1 [, id_var2 ...];

id_var1 and id_var2 which is a declared variable name, and type is the type of data set for id_var1 and id_var2. Example:

int liter, the price;
char name [20];

in the declaration of a variable can be initialisasi value of the variable. The general form of variable declarations and initialisasi are as follows.

[type] id_var1 = val_var1 [, id_var2 = val_var2 ...];

id_var1 and id_var2 which is a declared variable name, val_var2 is val_var1 and the initial value set at id_var1 and id_var2, and type is the type of data to and var_1 en id_var2. example:

int liter,
price = 385;
char name [20] = "Abdallah";

examples-3.1 program will prompt the user program to write his name, to define the variables, and then print a message in standard output media.

Program 3.1: SALAM.C
Code:

# include

char name [20],
prompt [20] = "Enter your name:";

main ()
(
printf (prompt);
scanf ( "% s", name);
printf ( "Hello% s. Congratulations to learn C. \ n", name);
)

if the program is run will display the following display.

Write your name: Grace
Hello Grace. Congratulations to learn C.

C. Arithmetic operations
Arithmetic operators used in C is generally equal to the symbol used to calculate the operation. Operator operators, utility, priorities, examples of expression and the result is as shown in Table 3.2

Table 3.2:
Arithmetic operators
Code:

Example operations operator expression results
-------- -------------- --------------- -----
* Multiplication 21 * 8 208
/ Division 27 / 3 9
% Remaining 30% division 4 2
+ Sum 2 +10 12
- Reduction of 29-13 16

Notes
* The operator% can not be used for the data types float or double.
* Operator * / and% have the same priority level, as well as the operator + with -, the first operator has a priority level higher than the second group.

Based on the expression rules that have been mentioned in the beginning of this chapter the implementation phases of dilalukan for arithmetic expressions like the following is stated by the next expression.

Code:

Implementation of Phase Expression
------------ -----------------
2 +3 * 4 2 +12
14
(2 +3) * 4 5 * 4
20
2 * 3% 4 6% 4
2
2 * (3% 4) 2 * 3
6
2 +3.0 / 4-5 2 +0.75-5
2.75-5
-2.25
(2 +3) / (4-5) 5 / (4-5)
5/-1
-5

Careful with your heart division. If the numerator and denominator integers of the results of this operation is also an integer form. To get results for a real number so one of the numerator and denominator must be real numbers. Example:

Code:

Result expression
-------- --------------
10 / 3 3
(float) 10 / 3 3.333333

D. RELATIONSHIP AND LOGIC OPERATION
The operation used to test the connection relationship between two Operands. The resulting value of this operation is 0 if false and -1 if true. Operators used are as shown in Table 3.3

Table 3.3:
Operator Relations
Code:

Operator Operation
-------- ---------------------
== Equals
! = Not equal to
Larger
<= Smaller or equal> = greater than or equal

Consider the example of service reduction and the value of relationships end in the following expression.
Code:

Result expression
---------- -----
2> 3 0
2! = 3 -1
5 == 4 * 10 * 2 -1

Priority relations operations is lower than arithmetic operations. Here is a sample implementation phases done for arithmetic expressions and relationships.
Code:

implementation phase expression
---------- -----------------
2 <5-3 3 =" 2" 2 ="=" 20 ="=" a =" a" a =" a-1" b =" a" b =" a" a =" a" b =" 3" b =" 3" aa =" a-1" b =" +" a =" a" b =" a" b =" 3" aa =" a-1" b =" 3" ac =" a" bb =" b" c =" a" ba =" a" id_var =" id_var" a =" 5" a =" a" op =" expression">>, &, ^, and |. Operation in top form implies.

id_var op id_var = expression

Example:
Code:

expression Eq
-------- ---------
x *= y-1 x = x * (y +1)
x + = 5 x = x +5
x>> = 3 x = x>> 3

3. Implementation Priorities and Direction Operator
The following table shows the level of priority and direction of implementation of the operator, which has been discussed whether or not yet. Operators located on the same line have the same priority level with the implementation in accordance with that stated in the next column.


Table 3.5:
Implementation Priorities and Direction Operator
Code:

Directions operator implementation
--------------------------- ------------------
() [] ->. From left to right
! ~ + + - - (Type) * & sizeof From right to left
* /% From left to right
+ - From left to right
<<>> From left to right
<<=>> = From left to right
==! = From left to right
& From left to right
^ From left to right
| From left to right
& & From left to right
| | From left to right
?: From right to left
= + = -=, Etc. From right to left
, From left to right

Tidak ada komentar:

Posting Komentar

.::BY JUMBHO-MY AT HOME IN THE JEPARA CITY OF BEAUTIFUL::.