Tải bản đầy đủ (.pdf) (695 trang)

IT training c data structures deshpande kakde 2004 01 15

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (8.14 MB, 695 trang )

ABC Amber CHM Converter Trial version, />
C & Data Structures
P. S. Deshpande
O. G. Kakde

CHARLES RIVER MEDIA, INC.
Hingham, Massachusetts
Copyright © 2003 Dreamtech Press
Reprint Copyright © 2004 by CHARLES RIVER MEDIA, INC.
All rights reserved.
No part of this publication may be reproduced in any way, stored in a retrieval system of any type, or
transmitted by any means or media, electronic or mechanical, including, but not limited to, photocopy,
recording, or scanning, without prior permission in writing from the publisher.
Acquisitions Editor: James Walsh
Production: Dreamtech Press
Cover Design: Sherry Stinson
CHARLES RIVER MEDIA, INC.
10 Downer Avenue
Hingham, Massachusetts 02043
781-740-0400
781-740-8816 (FAX)



Page 1


ABC Amber CHM Converter Trial version, />
P.S. Deshpande and O.G. Kakde. C & Data Structures
1-58450-338-6
All brand names and product names mentioned in this book are trademarks or service marks of their


respective companies. Any omission or misuse (of any kind) of service marks or trademarks should not be
regarded as intent to infringe on the property of others. The publisher recognizes and respects all marks used
by companies, manufacturers, and developers as a means to distinguish their products.
Library of Congress Cataloging-in-Publication Data
Deshpande, P. S.
C & data structures / P.S. Deshpande, O.G. Kakde.
p. cm.
ISBN 1-58450-338-6 (Paperback with CD-ROM : alk. paper)
1. C (Computer program language) 2. Data structures (Computer
science) I. Kakde, O. G. II. Title.
QA76.73.C15D48 2003
005.7'3—dc22
2003021572
04 7 6 5 4 3 2 First Edition
CHARLES RIVER MEDIA titles are available for site license or bulk purchase by institutions, user groups,
corporations, etc. For additional information, please contact the Special Sales Department at 781-740-0400.
Requests for replacement of a defective CD-ROM must be accompanied by the original disc, your mailing
address, telephone number, date of purchase and purchase price. Please state the nature of the problem,
and send the information to CHARLES RIVER MEDIA, INC., 10 Downer Avenue, Hingham, Massachusetts
02043. CRM's sole obligation to the purchaser is to replace the disc, based on defective materials or faulty
workmanship, but not on the operation or functionality of the product.
Acknowledgments
Writing any book is not an easy task. We spent about one year designing the contents, implementing the
programs and testing the programs. Our 12 years of teaching experience has helped us to explain the issues
in the language and complex problems in data structures.
We are thankful to our student Rupesh Nasre who, after receiving an M.Tech. degree in computer science
from IIT Mumbai, helped us in implementing advanced problems in data structures. We are also thankful to
our students Ms. Usha Agrawal and Mr. Ramchandra Vibhute for helping us in writing programs for II.

Page 2



ABC Amber CHM Converter Trial version, />
C & Data Structures
byP.S. DeshpandeandO.G. Kakde

ISBN:1584503386

Charles River Media 2004 (700 pages)

This thorough text provides a comprehensive guide to all the data types in C
with internal implementation, while providing examples to demonstrate their
behavior.

Table of Contents
C & Data Structures
Preface
Part I - C Language
Chapte
- Introduction to the C Language
r1
Chapte
- Data Types
r2
Chapte
- C Operators
r3
Chapte
- Control Structures
r4

Chapte
- The printf Function
r5
Chapte
- Address and Pointers
r6
Chapte
- The scanf Function
r7
Chapte
- Preprocessing
r8
Chapte
- Arrays
r9
Chapte
- Function
r 10
Chapte
- Storage of Variables
r 11
Chapte
- Memory Allocation
r 12
Chapte
- Recursion
r 13
Chapte
- Strings
r 14

Chapte
- Structures
r 15
Chapte
- Union
r 16
Chapte
- Files
r 17
Part II - Data Structures
Chapte - Arrays, Searching, and Sorting

Page 3


ABC Amber CHM Converter Trial version, />
r 18
Chapte
- Stacks and Queues
r 19
Chapte
- Linked Lists
r 20
Chapte
- Trees
r 21
Chapte
- Graphs
r 22
Part III - Advanced Problems in Data Structures

Chapte
- Problems in Arrays, Searching, Sorting, Hashing
r 23
Chapte
- Problems in Stacks and Queues
r 24
Chapte
- Problems in Linked Lists
r 25
Chapte
- Problems in Strings
r 26
Chapte
- Problems in Trees
r 27
Chapte
- Problems in Graphs
r 28
Chapte
- Miscellaneous Problems
r 29
Index
List of Figures
List of Tables
Back Cover
CD Content

Page 4



ABC Amber CHM Converter Trial version, />
Preface
The book is written for both undergraduate and graduate students of core computer science areas. The book
would be very useful for other students to learn programming for the purpose of making a career in computer
science. It covers all those topics that generally appear in aptitude tests and interviews. It not only gives the
language syntax but also discusses its behavior by showing the internal implementation. We have covered
almost the entire range of data structures and programming such as non-recursive implementation of tree
traversals, A* algorithm in Artificial Intelligence, 8-queens problems, etc. We also have supplied a CD-ROM
which contains all the source material that appears in the book. We welcome comments from our readers.

Page 5


ABC Amber CHM Converter Trial version, />
Part I: C Language
Chapter 1: Introduction to the C Language
Chapter 2: Data Types
Chapter 3: C Operators
Chapter 4: Control Structures
Chapter 5: The printf Function
Chapter 6: Address and Pointers
Chapter 7: The scanf Function
Chapter 8: Preprocessing
Chapter 9: Arrays
Chapter 10: Functions
Chapter 11: Storage of Variables
Chapter 12: Memory Allocation
Chapter 13: Recursion
Chapter 14: Strings
Chapter 15: Structures

Chapter 16: Union
Chapter 17: Files

Page 6


ABC Amber CHM Converter Trial version, />
Chapter 1: Introduction to the C Language
THE FIRST PROGRAM IN C
Introduction
The C program is a set of functions. The program execution begins by executing the function main (). You
can compile the program and execute using Turbo C compiler or using the following commands in Unix/Linux:
$ cc

-o a a.c

where a.c is the file in which you have written the program. This will create an executable file named a.exe.
$./a.
This will execute the program.

Program
#include <stdio.h>
main()
{
printf("Hello \n"); /* prints Hello on standard output */ }
Output : Hello

Explanation
1.
2.

3.
4.
5.

The program execution begins with the function main().
The executable statements are enclosed within a block that is marked by ‘{’ and ‘}’.
The printf() function redirects the output to a standard output, which in most cases is the
output on screen.
Each executable statement is terminated by ‘;’
The comments are enclosed in ‘/*...*/’

Variables
Introduction
When you want to process some information, you can save the values temporarily in variables. In the
following program you can define two variables, save the values, and put the addition in the third variable.

Program
#include <stdio.h>
main()
{
int i,j,k; // Defining variables Statement A
i = 6;

// Statement B

j = 8;
k = i + j;

Page 7



ABC Amber CHM Converter Trial version, />printf("sum of two numbers is %d \n",k); // Printing results
}
output : sum of two numbers is 14

Explanation
1.

2.
3.
4.

Statement A defines variables of the type integer. For each variable you have to attach some data
type. The data type defines the amount of storage allocated to variables, the values that they can
accept, and the operations that can be performed on variables.
The ‘ // ’ is used as single line comment.
The ‘%d’ is used as format specifier for the integer. Each data type has a format specifier that
defines how the data of that data type will be printed.
The assignment operator is ‘=’ and the statement is in the format:
Var = expression;

Points to Remember
1.
2.
3.

The variables are defined at the begining of the block.
The data type is defined at the begining of declaration and followed by a list of variables.
It is the data type that assigns a property to a variable.


Page 8


ABC Amber CHM Converter Trial version, />
INPUTTING THE DATA
Introduction
In C, the input from a standard input device, such as a keyboard, is taken by using the function scanf. In
scanf, you have to specify both the variables in which you can take input, and the format specifier, such as
%d for the integer.

Program
#include <stdio.h>
main()
{
int i,j,k;
scanf("%d%d",&i,&j);

// statement A

k = i + j;
printf("sum of two numbers is %d \n",k);
}
Input 3 4
Output:

sum of two numbers is 7

Explanation
1.


2.

3.

Statement A indicates the scanf statement that is used for taking input. In scanf you have to
specify a list of addresses of variables (&i, &j) which can take input. Before specifying the list of
variables you have to include a list of format specifiers that indicate the format of the input. For
example, for the integer data type the format specifier is %d.
In scanf, you have to specify the address of the variable, such as &i. The address is the
memory location where a variable is stored. The reason you must specify the address will be
discussed later.
The number of format specifiers must be the same as the number of variables.

Point to Remember
In scanf, you have to specify the address of a variable, such as &i, &j, and a list of format specifiers.

Page 9


ABC Amber CHM Converter Trial version, />
THE CONTROL STATEMENT (if STATEMENT)
Introduction
You can conditionally execute statements using the if or the if...else statement. The control of the
program is dependent on the outcome of the Boolean condition that is specified in the if statement.

Program
#include <stdio.h>
main()
{
int i,j,big;


//variable declaration

scanf("%d%d",&i,&j); big = i;
if(big < j)
{

// statement A

// C

big = j;
}

// Part Z, then part
// D

printf("biggest of two numbers is %d \n",big);
if(i < j)

// statement B

{
big = j;

// Part X

}
else
{

big = i;

// Part Y

}
printf("biggest of two numbers(using else) is %d \n",big);
}

Explanation
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Statement A indicates the if statement. The general form of the if statement is if(expr)

{
s1 ;
s2 ;
....
}
expr is a Boolean expression that returns true (nonzero) or false (zero).
In C, the value nonzero is true while zero is taken as false.
If you want to execute only one statement, opening and closing braces are not required, which is

indicated by C and D in the current program.
11. The else part is optional. If the if condition is true then the part that is enclosed after the if is
executed (Part X). If the if condition is false then the else part is executed (Part Y).
12. Without the else statement (in the first if statement), if the condition is true then Part Z is
executed.

Points to Remember
1.

if and if...else are used for conditional execution. After the if statement the control is

Page 10


ABC Amber CHM Converter Trial version, />
2.
3.

moved to the next statement.
If the if condition is satisfied, then the "then" part is executed; otherwise the else part is
executed.
You can include any operators such as <, >, <=, >=, = = (for equality). Note that when you want
to test two expressions for equality, use = = instead of =.

Page 11


ABC Amber CHM Converter Trial version, />
THE ITERATION LOOP (for LOOP)
Introduction

When you want to execute certain statements repeatedly you can use iteration statements. C has provided
three types of iteration statements: the for loop, while loop, and do...while loop. Generally, the
statements in the loop are executed until the specified condition is true or false.

Program

#include <stdio.h>
main()
{
int i,n;

//the

scanf("%d",&n);
for(i = 0; i
// statement A

{
printf("the numbers are %d \n",i); // statement B
}
}
/* input and output
5
the numbers are 0
the numbers are 1
the numbers are 2
the numbers are 3
the numbers are 4
*/


Explanation
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

Statement A indicates the for loop. The statements in the enclosing braces, such as statement
B, indicate the statements that are executed repeatedly because of the for loop.
The format of the for loop is
for (expr1;expr2;expr3)
{
s1;
s2 ; // repeat section
}
expr2 is a Boolean expression. If it is not given, it is assumed to be true.
The expressions expr1, expr2 and expr3 are optional.
expr1 is executed only once, the first time the for loop is invoked.
expr2 is executed each time before the execution of the repeat section.
When expr2 is evaluated false, the loop is terminated and the repeat section is not executed.

After execution of the repeat section, expr3 is executed. Generally, this is the expression that
is used to ensure that the loop will be terminated after certain iterations.

Points to Remember
1.

The for loop is used for repeating the execution of certain statements.

Page 12


ABC Amber CHM Converter Trial version, />2.
3.
4.

The statements that you want to repeat should be written in the repeat section.
Generally, you have to specify any three expressions in the for loop.
While writing expressions, ensure that expr2 is evaluated to be false after certain iterations;
otherwise your loop will never be terminated, resulting in infinite iterations.

Page 13


ABC Amber CHM Converter Trial version, />
THE do...while LOOP
Introduction
The do...while loop is similar to the while loop, but it checks the conditional expression only after the
repetition part is executed. When the expression is evaluated to be false, the repetition part is not executed.
Thus it is guaranteed that the repetition part is executed at least once.
Program

#include <stdio.h>
main()
{
int i,n;

//the

scanf("%d",&n);
i = 0;
do

// statement A

{
printf("the numbers are %d \n",i);
i = i +1;
}while( i}
/*
5
the numbers are 0
the numbers are 1
the numbers are 2
the numbers are 3
the numbers are 4
*/

Explanation
1.
2.

3.
4.
5.
6.
7.

Statement A indicates the do...while loop.
The general form of the do...while loop is
do
{
repetition part;
} while (expr);

When the do...while loop is executed, first the repetition part is executed, and then the
conditional expression is evaluated. If the conditional expression is evaluated as true, the repetition
part is executed again. Thus the condition is evaluated after each iteration. In the case of a normal
while loop, the condition is evaluated before making the iteration.
8. The loop is terminated when the condition is evaluated to be false.

Point to Remember
The do...while loop is used when you want to make at least one iteration. The condition should be

Page 14


ABC Amber CHM Converter Trial version, />
checked after each iteration.

Page 15



ABC Amber CHM Converter Trial version, />
THE switch STATEMENT
Introduction
When you want to take one of a number of possible actions and the outcome depends on the value of the
expression, you can use the switch statement. switch is preferred over multiple if...else statements
because it makes the program more easily read.

Program
#include <stdio.h>
main()
{
int i,n;

//the

scanf("%d",&n); for(i = 1; i{
switch(i%2) // statement A
{
case 0 : printf("the number %d is even \n",i); // statement B
break;

// statement C

case 1 : printf("the number %d is odd \n",i);
break;
}
}
}

/*
5
the number 1 is odd
the number 2 is even
the number 3 is odd
the number 4 is even
*/

Explanation
The program demonstrates the use of the switch statement.
1. The general form of a switch statement is
2.
3. Switch(switch_expr)
{
4.
case constant expr1 : S1;
5.
S2;
6.
break;
7.
case
constant
expr1
:
S3;
8.
S4;
9.
break;

10.
.....
11.
default
: S5;
12.
S6;
13.

Page 16


ABC Amber CHM Converter Trial version, />break;
14.
15. }
16. When control transfers to the switch statement then switch_expr is evaluated and the value
of the expression is compared with constant_expr1 using the equality operator.
17. If the value is equal, the corresponding statements (S1 and S2) are executed. If break is not
written, then S3 and S4 are executed. If break is used, only S1 and S2 are executed and
control moves out of the switch statement.
18. If the value of switch_expr does not match that of constant_expr1, then it is compared
with the next constant_expr. If no values match, the statements in default are executed.
19. In the program, statement A is the switch expression. The expression i%2 calculates the
remainder of the division. For 2, 4, 6 etc., the remainder is 0 while for 1, 3, 5 the remainder is 1.
Thus i%2 produces either 0 or 1.
20. When the expression evaluates to 0, it matches that of constant_expr1, that is, 0 as
specified by statement B, and the corresponding printf statement for an even number is
printed. break moves control out of the switch statement.
21. The clause ‘default’ is optional.


Point to Remember
The switch statement is more easily read than multiple if...else statements and it is used when you
want to selectively execute one action among multiple actions.

Page 17


ABC Amber CHM Converter Trial version, />
Chapter 2: Data Types
THE BUILT-IN DATA TYPES IN C
Introduction
Data types are provided to store various types of data that is processed in real life. A student's record might
contain the following data types: name, roll number, and grade percentage. For example, a student named
Anil might be assigned roll number 5 and have a grade percentage of 78.67. The roll number is an integer
without a decimal point, the name consists of all alpha characters, and the grade percentage is numerical
with a decimal point. C supports representation of this data and gives instructions or statements for
processing such data. In general, data is stored in the program in variables, and the kind of data the variable
can have is specified by the data type. Using this example, grade percentage has a float data type, and roll
number has an integer data type. The data type is attached to the variable at the time of declaration, and it
remains attached to the variable for the lifetime of the program. Data type indicates what information is stored
in the variable, the amount of memory that can be allocated for storing the data in the variable, and the
available operations that can be performed on the variable. For example, the operation S1 * S2, where S1
and S2 are character strings, is not valid for character strings because character strings cannot be multipled.

Program
// the program gives maximum and minimum values of data type
#include <stdio.h>
main()
{
int i,j ;// A

i = 1;
while (i > 0)
{
j = i;
i++;
}
printf ("the maximum value of integer is %d\n",j);
printf ("the value of integer after overflow is %d\n",i);
}

Explanation
1.
2.
3.

In this program there are two variables, i and j, of the type integer, which is declared in
statement A.
The variables should be declared in the declaration section at the beginning of the block.
If you use variables without declaring them, the compiler returns an error.

Points to Remember
1.
2.
3.

C supports various data types such as float, int, char, etc., for storing data.
The variables should be declared by specifying the data type.
The data type determines the number of bytes to be allocated to the variable and the valid
operations that can be performed on the variable.


Page 18


ABC Amber CHM Converter Trial version, />
VARIOUS DATA TYPES IN C
Introduction
C supports various data types for processing information. There is a family of integer data types and
floating-point data types. Characters are stored internally as integers, and they are interpreted according to
the character set. The most commonly used character set is ASCII. In the ASCII character set, A is
represented by the number 65.

Program/Examples
The data type families are as follows:
Integer family
char data type
int data type
short int data type
long int data type
These data types differ in the amount of storage space allocated to their respective variables. Additionally,
each type has two variants, signed and unsigned, which will be discussed later.
Float family (real numbers with decimal points)
Float data type
Double data type
(ANSI has also specified long double, which occupies the same storage space as double)

Explanation
1.
2.

Data type determines how much storage space is allocated to variables.

Data type determines the permissible operations on variables.

Points to Remember
1.
2.
3.

C has two main data type families: integer for representing whole numbers and characters of text
data, and float for representing the real-life numbers.
Each family has sub-data types that differ in the amount of storage space allocated to them.
In general, the data types that are allocated more storage space can store larger values.

Page 19


ABC Amber CHM Converter Trial version, />
THE INTEGER DATA TYPE FAMILY
Introduction
Integer data types are used for storing whole numbers and characters. The integers are internally stored in
binary form.

Program/Example
Here is an example that shows how integers are stored in the binary form.
Number =13
1
0
 Decimal representation = 1*10 + 3*10
3
2
1

 Binary representation = 1101 = 1*2 + 1*2 + 0*2 + 1*1
Each 1 or 0 is called a bit, thus the number 13 requires 4 bits.
In the same way, the number 130 is 1000 0010 in binary.
If the general data type is char, 8 bits are allocated. Using 8 bits, you can normally represent decimal
numbers from 0 to 255 (0000 0000 to 1111 1111). This is the case when the data type is unsigned char.
However, with signed char, the leftmost bit is used to represent the sign of the number. If the sign bit is 0,
the number is positive, but if it is 1, the number is negative.
Binary representation of the following numbers in signed char is as follows:
Number = 127 Binary representation = 0111 1111 (leftmost bit is 0, indicating positive.)
Number = −128 Binary representation = 1000 0000 (leftmost bit is 1, indicating negative.)
The negative numbers are stored in a special form called "2's complement". It can be explained as follows:
Suppose you want to represent −127:
1. Convert 127 to binary form, i.e. 0111 1111.
2. Complement each bit: put a 0 wherever there is 1 and for 0 put 1. So you will get 1000 0000.
3. Add 1 to the above number
4.
1000 0000
5.
+
1
6.
7. ------------1000 0001 (−127)
8.
8

8

Thus in the signed char you can have the range −128 to +127, i.e. (−2 to 2 −1).
The binary representation also indicates the values in the case of overflow. Suppose you start with value 1 in
char and keep adding 1. You will get the following values in binary representation:

0000 0001 (1)
0111 1111 (127)
1000 0000 (-128)
1000 0001 (-127)
In the case of unsigned char you will get
0000 0001 (1)
0111 1111 (127)

Page 20


ABC Amber CHM Converter Trial version, />1000 0000 (128)
1000 0001 (129)
1111 1111 (255)
0000 0000 (0)
This concept is useful in finding out the behavior of the integer family data types.
The bytes allocated to the integer family data types are (1 byte = 8 bits) shown in Table 2.1.
Table 2.1: Integer data type storage allocations
Data Type

Allocation

Range

signed char

1 byte

−2 to 2 −1 (−128 to 127)


Unsigned
char

1 byte

0 to 2 −1 (0 to 255)

short

2 bytes

−2 to 2 −1 (−32768 to 32767)

Unsigned
short

2 bytes

0 to 2 −1 (0 to 65535)

long int

4 bytes

2 to 2 −1 (2,147,483,648 to
2,147,483,647)

int

2 or 4 bytes depending on

implementation

Range for 2 or 4 bytes as given above

7

7

8

15

15

16

31

31

Explanation
1.
2.
3.
4.
5.

In C, the range of the number depends on the number of bytes allocated and whether the number
is signed.
If the data type is unsigned the lower value is 0 and the upper depends on the number of bytes

allocated.
If the data type is signed then the leftmost bit is used as a sign bit.
The negative number is stored in 2's complement form.
The overflow behavior is determined by the binary presentation and its interpretation, that is,
whether or not the number is signed.

Points to Remember
1.
2.

The behavior of a data type can be analyzed according to its binary representation.
In the case of binary representation, you have to determine whether the number is positive or
negative.

Page 21


ABC Amber CHM Converter Trial version, />
OVERFLOW IN char AND UNSIGNED char DATA TYPES
Introduction
Overflow means you are carrying out an operation such that the value either exceeds the maximum value or
is less than the minimum value of the data type.

Program
// the program gives maximum and minimum values of data type
#include <stdio.h>
main()
{
char i,j ;
i = 1;

while (i > 0) // A
{
j = i; // B
i++; // C
}
printf ("the maximum value of char is %d\n",j);
printf ("the value of char after overflow is %d\n",i);
}

Explanation
1.
2.

3.
4.
5.

This program is used to calculate the maximum positive value of char data type and the result of
an operation that tries to exceed the maximum positive value.
The while loop is terminated when the value of i is negative, as given in statement A. This is
because if you try to add 1 to the maximum value you get a negative value, as explained
previously (127 + 1 gives −128).
The variable j stores the previous value of i as given in statement B.
The program determines the maximum value as 127. The value after overflow is -128.
The initial value of i is 1 and it is incremented by 1 in the while loop. After i reaches 127, the
next value is -128 and the loop is terminated.

Points to Remember
1.
2.

3.

In the case of signed char, if you continue adding 1 then you will get the maximum value, and if
you add 1 to the maximum value then you will get the most negative value.
You can try this program for short and int, but be careful when you are using int. If the
implementation is 4 bytes it will take too much time to terminate the while loop.
You can try this program for unsigned char. Here you will get the maximum value, 255. The
value after overflow is 0.

Page 22


ABC Amber CHM Converter Trial version, />
THE char TYPE
Introduction
Alpha characters are stored internally as integers. Since each character can have 8 bits, you can have 256
different character values (0–255). Each integer is associated with a character using a character set. The
most commonly used character set is ASCII. In ASCII, "A" is represented as decimal value 65, octal value
101, or hexadecimal value 41.

Explanation
If you declared C as a character as
char c;
then you can assign A as follows:
c = 'A';
c = 65;
c = '\x41';

// Hexadecimal representation


c = '\101';

// Octal representation

You cannot write c = ‘A’ because ‘A’ is interpreted as a string.

Escape Sequence
Certain characters are not printable but can be used to give directive to functions such as printf. For
example, to move printing to the next line you can use the character "\n". These characters are called
escape sequences. Though the escape sequences look like two characters, each represents only a single
character.
The complete selection of escape sequences is shown here.
\a

alert (bell) character

\\

backslash

\b

backspace

\?

question mark

\f


form feed

\’

single quote

\n

new line

\"

double quote

\r

carriage return

\ooo

octal number

\t

horizontal tab

\xhh

hexadecimal number


\v

vertical tab

Points to Remember
1.
2.
3.

Characters are stored as a set of 255 integers and the integer value is interpreted according to
the character set.
The most common character set is ASCII.
You can give directive to functions such as printf by using escape sequence characters.

Page 23


ABC Amber CHM Converter Trial version, />
OCTAL NUMBERS
Introduction
You can represent a number by using the octal number system; that is, base 8. For example, if the number
1
is 10, it can be represented in the octal as 12, that is, 1*8 + 2*80.

Explanation
When octal numbers are printed they are preceeded by "%0".

Page 24



ABC Amber CHM Converter Trial version, />
HEXADECIMAL NUMBERS
Introduction
Hexadecimal numbers use base 16. The characters used in hexadecimal numbers are 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, A, B, C, D, E, and F. For example, if the decimal number is 22, it is represented as 16 in the
1
hexadecimal representation: 1*16 + 6*160 .

Explanation
You can print numbers in hexadecimal form by using the format "0x".

Page 25


×