Professional Documents
Culture Documents
POINTERS
A pointer is a variable that holds a memory address. Because it holds a memory address it is said to
be pointing to the value at that memory location. You can use a pointer in a certain way to get the
value at the address to which it points.
To declare a pointer: put a * in front of its name.
here is an examaple of how to declare a pointer to an integer and an untyped pointer:
int main()
{
int *p;
return 0;
}
You can put the address of an integer into a pointer to an integer by using the & operator to get the
integer's address.
int main()
{
int i;
int *p;
i = 5;
p = &i;
return 0;
}
You can access the value of the integer that is being pointed to by dereferencing the pointer. The * is
used to dereference a pointer. Changing the value pointed to by the integer will change the value of
the integer.
int main()
{
int i,j;
int *p;
i = 5;
p = &i;
j = *p; //j = i
*p = 7; //i = 7
return 0;
}
ARRAYS
Arrays are C data types that help us organize large amounts of information.
An array is an ordered list of values
A particular value in an array is referenced using the array name followed by the index in brackets
For example, the expression scores[2] refers to the value 94 (the 3rd value in the array)
That expression represents a place to store a single integer and can be used wherever an integer
variable can be used
Declaring array
It is possible to initialize an array when it is declared:
float prices[3] = {1.0, 2.1, 2.0};
Or to initialize it later:
int a[6];
a[0]=3;
a[1]=6;
Functions- also called subroutines, subprograms
allow complicated programs to be divided into small blocks – “divide and conquer”
a named sequence of statements that performs some useful procedure
is a complete and independent program
Argument - A value that you provide when you call a function. This value must have the same type as
the corresponding parameter.