You can optimize three different ways. One way is code optimization, another is logic optimization, and the last is data optimization. Code optimization is stuff like using pointers instead of indexes:

Code:

int array[10];
// slower
for ( int i = 0; i < size; i++ ) {
sum += array[i];
}
// faster
int *p = array;
int *end = array + size;
while ( p != end ) {
sum += *p++;
}

, reversing and unrolling loops:

Code:

int array[10];
// slower
for ( int i = 0; i < size; i++ ) {
sum += array[i];
}
// faster
for ( int i = 0; i < size / 2; i += 2 ) {
sum += array[i] + array[i + 1];
}

, and breaking early out of loops when the work is done or skipping over iterations when you don't need to do anything that time around. Logic optimization is picking better algorithms for what you're doing. Like using quicksort if you have a lot of things to sort, but bubblesort when you only have a hundred or so. Data optimization is picking the right data format to be fast, like when you can design your own import file. It's also data optimization when you pick the source of the data to be fast, like using a file instead of interactive input, or piping from another program instead of a file.