Hardware Reference
In-Depth Information
Constants
are often needed in forming a statement. There are four types of constants:
inte-
gers, characters, floating-point numbers,
and
strings.
There are seven
arithmetic operators
: 1, 2, *, /, %, 11, and 22. There are six
bitwise
operators
: &, |, ^, ,, .., and ,,. Bitwise operators can be applied only to integers.
Relational
operators
are used in control statements. They are 55, !5, ., .5, ,, ,5, &&, ||, and !.
The
control-flow statements
specify the order in which computations are performed. Con-
trol-flow statements include
if-else
statements,
multiway conditional
statements,
switch
statements,
for-loop
statements,
while
statements, and
do-while
statements.
Every C program consists of one or more functions. If a program consists of multiple func-
tions, their definitions cannot be embedded within another. The same function can be called
from several different places within a program. Generally, a function will process informa-
tion passed to it from the calling portion of the program and return a single value. Informa-
tion is passed to a function via special identifiers called
arguments
(also called
parameters
) and
returned via the
return
statement. Some functions, however, accept information but do not
return anything (for example, the library function
printf
).
A
pointer
holds the address of a variable. Pointers can be used to pass information back
and forth between a function and its reference (calling) point. In particular, pointers provide a
way to return multiple data items from a function via function arguments. Pointers also permit
references to other functions to be specified as arguments to a given function. Two operators are
related with pointers: * and &. The
*
operator returns the value of the variable pointed to by the
pointer. The
&
operator returns the address of a variable.
Data items that have common characteristics are placed in an
array
. An array may be one-
dimensional or multidimensional. The dimension of an array is specified by the number of
square bracket pairs [ ] following the array name. An array name can be used as an argument to
a function, thus permitting the entire array to be passed to the function. To pass an array to a
function, the array name must appear by itself, without brackets or subscripts. An alternative
way to pass arrays to a function is to use pointers.
A variable defined inside a function is an
internal variable
of that function.
External vari-
ables
are defined outside of any function and are thus potentially available to many functions.
The
scope
of a name is the part of the program within which the name can be used. The scope
of an external variable or a function lasts from the point at which it is declared to the end of the
file being compiled.
Tutorials for using the CodeWarrior IDE and ImageCraft ICC12 are provided at the end of
this chapter. The tutorial for using the EGNU IDE is in Appendix E. All three IDEs are window
driven, but only CodeWarrior provides source-level debugging capability.
Neither ImageCraft nor EGNU IDEs provides many library functions to the user. Three sets
of library functions are provided in the complementary CD and are listed in Table E.1 of Appen-
dix E. These three sets of library functions are stored in files
stdio0.c, delay.c,
and
convert.c
.
E5.1
Assume that
ax
5 83 and
bx
5 11. What is the value of
ax
/
bx
?
E5.2
Assume that
ax
5 97 and
bx
5 ax % 23. What is the value of
bx
?
E5.3
Assume that
ax
5 0x39 and
bx
5
ax
^ 0x79. What is the value of
bx
?
E5.4
Assume that
ax
5 0x9D and
bx
5
ax
,, 2. What is the value of
bx
?
E5.5
Assume that
ax
5 0x6B and
bx
5
ax
& 0xDE. What is the value of
bx
?
E5.6
Write a C function to test whether an integer is a multiple of 8. If the number to be tested
is a multiple of 8, the function returns a 1 to the caller. Otherwise, it returns a 0 to the caller.
Search WWH ::
Custom Search