Week 3

From CDOT Wiki
Revision as of 14:10, 27 May 2010 by Jaburton1 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

What is a platform? - a combination of a CPU, OS and compiler.

What is an address? An unsigned integer (no negative numbers)

Why have pointers and not just unsigned ints? Because pointers do not show us what type of variable we are working with. For example, when working with this: unsigned int b = &a; we have no idea what type of variable the address of a is holding.

What is the real difference?

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)


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