Review + pre-req: what is a
data type
A
data type in
a programming language
provides these
features to
the programmer:
- The programmer can
define (= create)
variables of
the data type to
store values
of the data type
- A data type also
provide
specialized
operations on the
values of the
data type
|
Example:
Data type int: represent whole values
(1) Defining variables: int x, y, z;
(2) Specialized operations for int: +, -, *, /, %
x = x + y;
|
Prelude to
the reference
data type - review: what is a
reference
Reference data type
-
Reference data type =
a data type
uses
integer numbers as
memory addresses
- The
reference data type in
C allows
C programmers to:
- Define
variables of a
reference type that
can
store
memory addresses
(I.e.: a reference typed variable
stores an
integer that
is
used
as a memory addresses
- Apply
special operations
(& and
*) that
uses
memory addresses (= integers)
to achive
specialized effects
|
|
The reference
data
types
in
C
Defining a reference typed variable
Defining a reference typed variable -
Example
- Examples:
int a, *p; // a stores an integer value
// p stores an address of
// an int typed variable
float b, *q; // b stores a float value
// q stores an address of
// a float typed variable
|
|
Note: the
symbol
* is
also used
as the
multiply operator (e.g.:
x *
y)
Note:
* used
as multiply operation is
a binary operator
Note:
* used
as reference operation is
an unary operator
Note on the syntax to
define reference typed variables
Operations on address values
❮
❯