Changes

Jump to: navigation, search

Week 3

1,155 bytes added, 15:10, 27 May 2010
no edit summary
The real difference is that when you add one to a pointer, it doesn't just add one, it adds 4 bytes (it wants to go to the next integer in memory - or 8 bytes for double, etc). Pointer rithmetic
 
An array int a[10] will create 10 integers, and then create a pointer to the beginning of that list of integers.
 
*b = where b is pointing to
&a = the address of a
int* = pointer
 
a[0] is the same as *a. they are the same.
 
when you move one integer in the array
 
a[1] it moves 4 bytes over to the next integer.
 
Arrays are nothing buy pointers.
 
After creating an array you can just refer to it as "a" when wanting to get the pointer.
 
In creating 2D arrays, the pointer for the array is created to be as large as 1 array, so when you say a+1 it skips the entire first array and goes to the next one.
 
 
a[3][5][6][9]
point notation:
*(*(*(*(a+3)+5)+6)+9)
 
done.
 
Lazy evaluation - checks the first condition and doesn't bother with the next && condition because the first condition determines the whole condition.
 
Operators are operators in C so if you can use + without an if statement, you can use conditional operators without an if statement:
 
a[i]>3 && printf("%d\n", a[i]);
 
that will print all numbers greater than 3 in the array of a.
 
the default for && to continue is true, false to stop
the default for || to continue is false, true to stop
1
edit

Navigation menu