2. Pointers
Pointers are memory addresses variables i.e. the variables, which have
addresses of the variables having some value, stored in the memory.
It represented as :
variable memory memory memory
name value address variable
q 280 6000 p
(pointer)
3. Declaring a Pointer Variable (Initialization of Pointer):
A pointer variable should be declared before they are used. If a variables
going to hold a pointer, it must be declared as such. A pointer declaration
consists of a base type, an * , and variable name. base type define data
type………… its used in beginning of the main program.
Syntax :-
data-type *pointer-variable ;
int *m; ,
float * y; ,
char * z; ……………….
4. Expressions
An expression is a combination of operands and operators. It is a combination
of two or more than two operands or many operators.
Example:- a+b*c/d and so on………….
5. Pointers expression
Pointers deals with the arithmetic, relational, logical and assignment expressions.
Pointers are not directly used in the arithmetic, relational, logical and assignment
expression, only pointer values are used. Some of the arithmetic expression used
with pointer p1 and p2 as follow:
Int x, y, *p1, *p2, z, a, b, c;
x = 10;
y = 20;
p1 = &x;
p2 = &y;
Z = (*p1)/(*p2);
a = (*p1)*(*p2);
b = (*p1)+(*p2);
c = (*p1)-(*p2);
6. Array
Array is similar type of data collection name i.e. it is a collection of same
data type elements. An array is a group of related data items, which share
common name.
“It is the set of homogenous data”
a(0) a(1) a(3) a(4) or a{0., 1, 2, 3, 4}
7. Pointers with Array
Pointers have close relationship with array. Pointers are linked with array
by taking its first element number and its base address. Suppose an array
of integer type, which is as defined as below:
Static int a[5] = {25, 30, 35, 40, 45}
Its can be represented in the computer memory as;
a(0) a(1) a(2) a(3) a(4)
Value address 25 30 35 40 45
1000 1002 1004 1006 1008
8. Pointers and Function:
We can pass pointer to the function and also pointer addresses can be
passed to the function as pointer arguments. This can be represented by
two ways…………..
A). Pointer as function argument
B) Pointer to function
9. Pointer as function argument
1) Call by reference
2) call by value
swapping: exchanging of value from one variable to another……..
ex = X and Y
10. Dynamic Memory Allocation
In dynamic memory allocation of the memory, the declaration of variable is
no longer required. The job of memory allocation can be done bye using the
three functions……
1) maclloc():
2) calloc():
3) realoc():