Professional Documents
Culture Documents
U.U.Samantha Rajapaksha
B.Sc.(Eng.)
There are things and pointers to things. Knowing the difference between the two is
very important.
The address of thing is 0x1000. Addresses are automatically assigned by the C
compiler to every variable. Normally, you don't have to worry about the addresses
of variables, but you should understand that they're there.
Our pointer (thing_ptr) points to the variable thing. Pointers are also called
address variables because they contain the addresses of other variables. In this
case, our pointer contains the address 0x1000.
#include <stdio.h>
void inc_count(int *count_ptr)
{
(*count_ptr)++;
}
int main() {
int count = 0; /* number of times through */
while (count < 10)
inc_count(&count);
return (0);
}
Finally, we can put const in both places, creating a pointer that cannot
be changed to a data item that cannot be changed:
function definition
DAA 214 Lab 02 Sri Lanka Institute of Information Technology.
Exercise
Write a program to read a set of numbers and store them on an array.
Write function named as partition to divide the array into two parts according to the partition
point.
Call the function from the main program.
PARTITION(A, p, r)
1 x ← A[r]
2i←p-1
3 for j ← p to r - 1
4 do if A[j] ≤ x
5 then i ← i + 1
6 exchange A[i] ↔ A[j]
7 exchange A[i + 1] ↔ A[r]
8 return i + 1
DAA 214 Lab 02 Sri Lanka Institute of Information Technology.