Page 68 - DCAP407_DATA_STRUCTURE
P. 68
Unit 4: Pointers
A pointer to pointer can be declared as:
int ** x;
int can be accessed by dereferencing the pointer.
j= **x; //assign an integer to j
Consider the following:
int b = 5;
int *c = &b
int ** d = &c;
Here, both c and d contain the address of an int, while d contains the address of a pointer to an int.
There are three ways to update the value of variable b to 10. They are:
a= 10;
or
*b= 10;
or
**c=10;
All of them will set the value 10 to the variable b.
typedef keyword can be used to assign name to type definition and use the type name to declare the
variables. Syntax for defining names using typedef in pointers is shown below:
typedef known_type_definition new_type_name
Here, known_type_definition is the data type like, int, char, and float.
new_type_name is the new variable name
typedef int *Inpt
Inpt pointer1, pointer2;
The new type name is used to declare pointer variables of type pointer to
integers.
Did you know?
Address is a machine-level reference to a location in memory space of a process.
1. “&” is the reference operator and is read as “address of.”
2. “*” is the dereference operator and is read as “value pointed by.”
3. A variable name referenced with “&” can be dereferenced with “*”.
LOVELY PROFESSIONAL UNIVERSITY 61